├── main.py ├── mongodb_py ├── tempCodeRunnerFile.py ├── json_data.py ├── 2-fetch.py ├── 3-insert_many.py ├── 4-candidate_info.py ├── 1-connect.py ├── 5-email_checking.py ├── tcp_server_mongo.py └── tcp_client_mongo.py ├── hellotest.js ├── xxxForTest.py ├── nist.txt ├── x_Voting ├── voting_program.py ├── __pycache__ │ └── voting_lib.cpython-311.pyc └── voting_lib.py ├── .idea ├── vcs.xml ├── misc.xml ├── .gitignore ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── nistdic2.iml ├── 10-Dictionary.py ├── 9-listinlist.py ├── nistdb.txt ├── winTest.py ├── 6-parameters.py ├── 19-file_and_string.py ├── 18-FIO.py ├── 11-deepDictionary.py ├── 2-lesson.py ├── 3-condition_sample_program.py ├── 13-testing_program.py ├── 7-gameProgram.py ├── 8-python_list.py ├── 4-lessonWhileTest.py ├── 2-OOP_Code └── 1-oop.py ├── 5-functionLesson.py ├── 12-list_methods.py ├── Dip2-Auction ├── client.py └── server.py ├── 14-registration.py ├── 21-method_for_recording.py ├── 16-adding_more_data.py ├── 15-completeRE.py ├── 17-data_record.py └── 20-recordingDataToFile.py /main.py: -------------------------------------------------------------------------------- 1 | print("Hello PYthon") -------------------------------------------------------------------------------- /mongodb_py/tempCodeRunnerFile.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /hellotest.js: -------------------------------------------------------------------------------- 1 | function myfun(){ 2 | 3 | console.log("WinHtut") 4 | 5 | 6 | } -------------------------------------------------------------------------------- /xxxForTest.py: -------------------------------------------------------------------------------- 1 | txt = "win@gmail.com winhtut winpass 0997 100" 2 | 3 | x = txt.split(" ") 4 | 5 | print(x) -------------------------------------------------------------------------------- /nist.txt: -------------------------------------------------------------------------------- 1 | N 2 | a 3 | t 4 | i 5 | o 6 | n 7 | a 8 | l 9 | I 10 | n 11 | s 12 | t 13 | i 14 | t 15 | u 16 | t 17 | e 18 | -------------------------------------------------------------------------------- /x_Voting/voting_program.py: -------------------------------------------------------------------------------- 1 | from voting_lib import Voting 2 | 3 | if __name__ == '__main__': 4 | voting = Voting() 5 | voting.main_option() -------------------------------------------------------------------------------- /x_Voting/__pycache__/voting_lib.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winhtut/For-Scholarcharship-Dip-2/HEAD/x_Voting/__pycache__/voting_lib.cpython-311.pyc -------------------------------------------------------------------------------- /mongodb_py/json_data.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | data = {"name":"a3","email":"win@","pass":"password123"} 4 | 5 | myapi =json.dumps(data) 6 | print(myapi) 7 | print(type(myapi)) 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /10-Dictionary.py: -------------------------------------------------------------------------------- 1 | my_dict = {"name":{ 2 | 3 | "home_name":"winwin", 4 | "school_name":"htuthtut" 5 | },"hobby":["r&d","programming","computerscience"]} 6 | 7 | print(my_dict["name"]["home_name"]) 8 | print(my_dict["hobby"][1]) -------------------------------------------------------------------------------- /9-listinlist.py: -------------------------------------------------------------------------------- 1 | my_list = [10,["win",["R&D","ComputerScience"],'nist'],30,40,50,"programming"] 2 | 3 | print(my_list[1][0]) 4 | 5 | 6 | length = len(my_list) 7 | 8 | my_list[-1]="NIST" 9 | 10 | print(type(my_list[1][1][1])) -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /nistdb.txt: -------------------------------------------------------------------------------- 1 | win@gmail.com winpass winpass 99 100 2 | 1win@gmail.com winpass winpass 99 100 3 | 2win@gmail.com winpass winpass 99 100 4 | 3win@gmail.com winpass winpass 99 100 5 | nist@gmail.com NIST nistpass 1991 100 6 | ux@gmail.com ux uxpass 1999 100 -------------------------------------------------------------------------------- /winTest.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | output = subprocess.getoutput("dir") 4 | #result = output.stdout.decode() 5 | 6 | #return_valued = os.system(received_data) 7 | print("*****************\n", output) 8 | print("********************") -------------------------------------------------------------------------------- /6-parameters.py: -------------------------------------------------------------------------------- 1 | def add(a,b,c): 2 | print("Hello") 3 | return a+b+c 4 | def subtract(firstNumber, secondNumber): 5 | print(firstNumber-secondNumber) 6 | first = 10 7 | second = 20 8 | third = 30 9 | result =add(first,second,third) 10 | subtract(third,second) 11 | print(result) 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /19-file_and_string.py: -------------------------------------------------------------------------------- 1 | datas = "NationalInstitute" 2 | 3 | some_text = "Hello i am from Heaven" 4 | 5 | with open("nist.txt",'w') as winhtut: 6 | for element in datas: 7 | winhtut.write(element) 8 | winhtut.write('\n') 9 | 10 | # with open("nist.txt",'w') as file: 11 | # file.write(some_text) -------------------------------------------------------------------------------- /18-FIO.py: -------------------------------------------------------------------------------- 1 | datas = ["candc++","national","institute","of science"] 2 | 3 | some_text = "Hello i am from Heaven" 4 | 5 | with open("nist.txt",'w') as file: 6 | for element in datas: 7 | file.write(element) 8 | file.write('\n') 9 | 10 | # with open("nist.txt",'w') as file: 11 | # file.write(some_text) -------------------------------------------------------------------------------- /11-deepDictionary.py: -------------------------------------------------------------------------------- 1 | #deep dictionary 2 | # data = key:value ဒေတာ တစ်ခု 3 | 4 | 5 | d_data = {"name":{"computer":["lenovo","dell","acer"]}, 6 | "c_type":{"lenovo":["i5","i3","i9"]}, 7 | 8 | 9 | "type":"Institute","org":"research",1:[1,2,3,4,5]} 10 | 11 | print(d_data["name"]["computer"][0],d_data["c_type"]) -------------------------------------------------------------------------------- /2-lesson.py: -------------------------------------------------------------------------------- 1 | # control structure 2 | # if else for while do while switch case break 3 | 4 | # looping အကြိမ်ကြိမ် အလုပ်ုလပ်စေချင်ရင် Looping ကိုသုံးတယ် 5 | 6 | # range( start , stop , step ) ဘယ်လောက် ပေါင်းသွားမလဲ 7 | for a in range(3,10,2): 8 | print(a,"Hello Python and NIST") 9 | for i in range(2,a,2): 10 | print("The second loop---------",i) 11 | 12 | -------------------------------------------------------------------------------- /mongodb_py/2-fetch.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | 3 | connection =pymongo.MongoClient("localhost",27017) 4 | database =connection["ncc_dip2"] 5 | collection =database["user_info"] 6 | r_email =input("Enter your email to register:") 7 | 8 | for i in collection.find({},{"_id":0,"email":1}): 9 | if r_email == i["email"]: 10 | print("Already Register ") 11 | break 12 | 13 | 14 | -------------------------------------------------------------------------------- /3-condition_sample_program.py: -------------------------------------------------------------------------------- 1 | 2 | user_name="NIST" 3 | user_pass="nist123" 4 | user_input =int(input("Enter some number:")) 5 | 6 | for i in range(user_input): 7 | l_name =input("Enter your username:") 8 | l_pass = input("Enter your password:") 9 | 10 | if l_name==user_name and l_pass==user_pass: 11 | print("Login success") 12 | else: 13 | print("Login Failed") -------------------------------------------------------------------------------- /.idea/nistdic2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /13-testing_program.py: -------------------------------------------------------------------------------- 1 | #test_program 2 | 3 | db={} 4 | 5 | def insertion(): 6 | 7 | user_email = input("Enter your email:") 8 | user_password = input("Enter your password:") 9 | id = len(db) 10 | 11 | to_insert ={id: {"email":user_email,"password":user_password}} 12 | db.update(to_insert) 13 | 14 | if __name__ == '__main__': 15 | for i in range(3): 16 | insertion() 17 | 18 | print(db) -------------------------------------------------------------------------------- /7-gameProgram.py: -------------------------------------------------------------------------------- 1 | def age_checking(age): 2 | if age<18: 3 | print("You cannot play game") 4 | elif age>=18 and age<40: 5 | print("you can play game") 6 | else: 7 | print("Invalid") 8 | 9 | 10 | def home_page(): 11 | user_name = input("Enter your name:") 12 | user_age = int(input("Enter your age:")) 13 | 14 | age_checking(user_age) 15 | 16 | 17 | 18 | 19 | home_page() -------------------------------------------------------------------------------- /8-python_list.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | my_data=[10,20,30,40,50,60] #list 5 | # 0 1 2 3 4 5 6 | 7 | print(len(my_data)) 8 | print("Before",my_data) 9 | my_data[0]=100 #update 10 | 11 | print("After",my_data) 12 | my_data.append(200) 13 | print(my_data.insert(5,"WinHtut")) 14 | print("After Append",my_data) 15 | 16 | my_reversed = reversed(my_data) 17 | 18 | for i in my_reversed: 19 | print(i) 20 | 21 | print(None) -------------------------------------------------------------------------------- /4-lessonWhileTest.py: -------------------------------------------------------------------------------- 1 | user_name = "NIST" 2 | user_pass = "nist123" 3 | 4 | counter = 0 5 | 6 | while True: 7 | l_name = input("Enter your username:") 8 | l_pass = input("Enter your password:") 9 | 10 | if l_name == user_name and l_pass == user_pass: 11 | print("Login success") 12 | else: 13 | counter = counter + 1 14 | print("Login Failed") 15 | if counter == 3: 16 | print("Wait a time") 17 | break 18 | -------------------------------------------------------------------------------- /2-OOP_Code/1-oop.py: -------------------------------------------------------------------------------- 1 | #OOP object oriented programming 2 | #method 3 | 4 | class Nist: 5 | 6 | def __init__(self,data): #special method class ကိုအခေါ် ခံရတာနဲ့ တန်းပြီးအလုပ်လုပ်တယ် 7 | print("Special Method!") 8 | self.someData = data 9 | print(self.someData) 10 | def myFun(self): 11 | print("This is from myFun") 12 | 13 | def myFun2(self): 14 | print("This is from myFun2") 15 | print(self.someData) 16 | 17 | 18 | 19 | ux =Nist("ux") 20 | 21 | -------------------------------------------------------------------------------- /5-functionLesson.py: -------------------------------------------------------------------------------- 1 | #python functions 2 | # what is function? 3 | # how does function work? 4 | 5 | def mgmg(): 6 | print("This is mgmg") 7 | print("Developer") 8 | print("From Yangon") 9 | 10 | def agag(): 11 | print("This is agag") 12 | print("Hacker") 13 | print("From PyinOoLwin") 14 | 15 | 16 | userName = input("Enter name:") #parameter 17 | 18 | if userName=="mgmg": 19 | mgmg() 20 | else: 21 | agag() 22 | 23 | 24 | 25 | # programming languages -> keywords 26 | 27 | -------------------------------------------------------------------------------- /12-list_methods.py: -------------------------------------------------------------------------------- 1 | import copy 2 | mylist = [1,2,3,['a','b','c']] 3 | 4 | mylist2 = ['d','e','f'] 5 | # mylist.append(mylist2) 6 | # print(mylist) 7 | 8 | mylist3 = copy.copy(mylist) 9 | mylist.append('here') 10 | print("mylist id",id(mylist) , mylist) 11 | print("mylist3 id",id(mylist3),mylist3) 12 | 13 | 14 | mydlist = [1,2,3,['a','b','c']] 15 | 16 | mydlist2 = copy.deepcopy(mydlist) 17 | mydlist.append("dcopy") 18 | print("mydlist",id(mydlist),mydlist) 19 | print("mydlist2",id(mydlist2),mydlist2) 20 | 21 | 22 | print("#######################") 23 | 24 | testList = [1,2,3,4] 25 | testlist2 = testList 26 | testList.append("hello") 27 | print(testList,id(testList)) 28 | print(testlist2,id(testlist2)) 29 | 30 | -------------------------------------------------------------------------------- /mongodb_py/3-insert_many.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | 3 | import random 4 | connection = pymongo.MongoClient("localhost", 27017) 5 | database = connection["ncc_dip2"] 6 | collection = database["user_info"] 7 | 8 | if __name__ == '__main__': 9 | 10 | for i in range(10): 11 | user_id = random.randint(10, 10000) 12 | email: str = "win"+str(i)+"@gmail.com" 13 | password: str = "12345" 14 | phone: int = 94537 15 | point: int = 100 16 | 17 | info:str = "User data is Win"+str(i)+"id : "+str(user_id) 18 | 19 | data_form = {"_id": user_id, "email": email, "password": password, "phone": phone,"info":info,"point":point} 20 | 21 | ids = collection.insert_one(data_form) 22 | print("inserted id :", ids.inserted_id) -------------------------------------------------------------------------------- /mongodb_py/4-candidate_info.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | 3 | import random 4 | connection = pymongo.MongoClient("localhost", 27017) 5 | database = connection["ncc_dip2"] 6 | collection = database["candidate"] 7 | 8 | if __name__ == '__main__': 9 | 10 | for i in range(10): 11 | user_id = random.randint(10, 10000) 12 | name: str = "ncc"+str(i) 13 | email: str = "win"+str(i)+"@gmail.com" 14 | 15 | phone: int = 94537 16 | vote_point:int=0 17 | 18 | info:str = "Candidate Info "+str(i)+"id : "+str(user_id) 19 | 20 | data_form = {"_id": user_id,"name":name ,"email": email, "phone": phone,"info":info,"vote_point":vote_point} 21 | 22 | ids = collection.insert_one(data_form) 23 | print("inserted id :", ids.inserted_id) -------------------------------------------------------------------------------- /mongodb_py/1-connect.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | 3 | import random 4 | connection = pymongo.MongoClient("localhost", 27017) 5 | database = connection["ncc_dip2"] 6 | collection = database["user_info"] 7 | 8 | if __name__ == '__main__': 9 | 10 | while True: 11 | try: 12 | user_id = random.randint(10, 10000) 13 | email: str = input("Enter useremail:") 14 | password: str = input("Enter user password:") 15 | phone: int = int(input("Enter user phone:")) 16 | 17 | data_form = {"_id": user_id, "email": email, "password": password, "phone": phone} 18 | 19 | ids = collection.insert_one(data_form) 20 | print("inserted id :", ids.inserted_id) 21 | except Exception as err: 22 | print(err) 23 | -------------------------------------------------------------------------------- /Dip2-Auction/client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | 4 | class TCPclient(): 5 | def __init__(self, sms): 6 | self.target_ip = 'localhost' 7 | self.target_port = 9998 8 | self.send_and_recv_data = {} 9 | 10 | self.client_sms = bytes(sms, 'utf-8') 11 | 12 | self.send_and_recv_data.update({len(self.send_and_recv_data): sms}) 13 | 14 | def run_client(self): 15 | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 16 | client.connect((self.target_ip, self.target_port)) 17 | 18 | client.send(self.client_sms) 19 | 20 | received_from_server = client.recv(4096) 21 | 22 | recv_sms = received_from_server.decode("utf-8") 23 | 24 | self.send_and_recv_data.update({len(self.send_and_recv_data):recv_sms}) 25 | print("Get Back Data from Server:",recv_sms) 26 | 27 | client.close() 28 | 29 | 30 | if __name__ == "__main__": 31 | while True: 32 | sms = input("Enter some data to send:") 33 | tcp_client = TCPclient(sms) 34 | tcp_client.run_client() 35 | -------------------------------------------------------------------------------- /14-registration.py: -------------------------------------------------------------------------------- 1 | # def adding(a,b): 2 | # c = a+b 3 | # return c 4 | # 5 | # 6 | # if __name__ == '__main__': 7 | # result =adding(1,2) 8 | # print(result) 9 | 10 | # သွားခေါ်တဲ့ function သည် return ပြန် ပေးရင် ခေါ်တဲ့ နေရာကလည်း ပြန်လက်ခံ ပေးရမယ် 11 | 12 | 13 | 14 | #test_program 15 | 16 | db={} 17 | 18 | def main_sector(): 19 | main_option =int(input("Press 1 to Register:\nPress 2 to Login\nPress 3 Exit:")) 20 | if main_option== 1: 21 | registration() 22 | elif main_option==2: 23 | login() 24 | elif main_option==3: 25 | exit(1) 26 | else: 27 | print("Invalid Option") 28 | main_sector() 29 | 30 | def registration(): 31 | 32 | user_email = input("Enter your email:") 33 | user_password = input("Enter your password:") 34 | id = len(db) 35 | 36 | to_insert ={id: {"email":user_email,"password":user_password}} 37 | db.update(to_insert) 38 | 39 | def login(): 40 | user_found=-1; 41 | print("This is login sector") 42 | l_user_email = input("Enter your email to login:") 43 | l_user_password = input("Enter your password to login:") 44 | 45 | for i in range(len(db)): 46 | if db[i]["email"] == l_user_email and db[i]["password"]==l_user_password: 47 | 48 | user_found=i 49 | if user_found!=-1: 50 | print("Login Success!") 51 | user_profile(l_user_email) 52 | else: 53 | print("Not Found ") 54 | def user_profile(info): 55 | print("Welcome:",info) 56 | 57 | if __name__ == '__main__': 58 | while True: 59 | main_sector() -------------------------------------------------------------------------------- /mongodb_py/5-email_checking.py: -------------------------------------------------------------------------------- 1 | def email_checking(r_email): 2 | name_counter =0 3 | for i in range(len(r_email)): 4 | if r_email[i]=='@': 5 | #print("Name End Here") 6 | break 7 | name_counter +=1 8 | 9 | print("Name counter: ",name_counter) 10 | 11 | email_name = r_email[0:name_counter] 12 | email_form = r_email[name_counter:] 13 | 14 | #print(email_name) 15 | print(email_form) 16 | 17 | #checking for name 18 | name_flag=0 19 | email_flag=0 20 | for i in range(len(email_name)): 21 | aChar = email_name[i] 22 | if (ord(aChar) >31 and ord(aChar) < 48 ) or ( ord(aChar) >57 and ord(aChar) < 65) or ( ord(aChar) >90 and ord(aChar)<97) or (ord(aChar) >122 and ord(aChar) < 128 ): 23 | 24 | name_flag = -1 25 | break 26 | 27 | domain_form=["@facebook.com","@ncc.com","@mail.ru","@yahoo.com","@outlook.com","@apple.com","@zoho.com","@gmail.com"] 28 | 29 | for i in range(len(domain_form)): 30 | 31 | if domain_form[i] == email_form: 32 | email_flag= 1 33 | break 34 | 35 | 36 | if name_flag == -1 or email_flag== 0 : 37 | return -1 38 | 39 | else: 40 | return 1 41 | 42 | 43 | 44 | if __name__ == '__main__': 45 | 46 | 47 | 48 | 49 | while True: 50 | email =input("Enter valid email ") 51 | flag =email_checking(email) 52 | if flag==1: 53 | print("Email form valid") 54 | else : 55 | print("Not valid!") -------------------------------------------------------------------------------- /21-method_for_recording.py: -------------------------------------------------------------------------------- 1 | # nistdb = {0:{'email': 'win@gmail.com', 'u_name': 'winpass', 'password': 'winpass', 'phone': 99, 'age': 100}, 2 | # 3 | # 1:{'email': '1win@gmail.com', 'u_name': 'winpass', 'password': 'winpass', 'phone': 99, 'age': 100}, 4 | # 2:{'email': '2win@gmail.com', 'u_name': 'winpass', 'password': 'winpass', 'phone': 99, 'age': 100}, 5 | # 3:{'email': '3win@gmail.com', 'u_name': 'winpass', 'password': 'winpass', 'phone': 99, 'age': 100} 6 | # 7 | # } 8 | 9 | nistdb={} 10 | 11 | #print(nistdb) 12 | 13 | 14 | #print(nistdb.keys()) 15 | 16 | 17 | def recording_all_data(): 18 | with open("nistdb.txt", 'w') as dbfile: 19 | for i in range(len(nistdb)): 20 | email = nistdb[i]["email"] 21 | user_name = nistdb[i]["u_name"] 22 | password = nistdb[i]["password"] 23 | phone = nistdb[i]["phone"] 24 | age = nistdb[i]["age"] 25 | total_user_data = email + ' ' + user_name + ' ' + password + ' ' + str(phone) + ' ' + str(age) + '\n' 26 | 27 | dbfile.write(total_user_data) 28 | # print("data:", email, user_name, password, phone, age) 29 | #print("Recorded") 30 | 31 | def loading_data_from_file(): 32 | 33 | 34 | with open("nistdb.txt",'r') as dbfile: 35 | datas=dbfile.readlines() 36 | for one in datas: 37 | oneData = one.split(" ") 38 | 39 | id = len(nistdb) 40 | data_form = {id:{"email":oneData[0],"u_name":oneData[1],"password":oneData[2], 41 | "phone":oneData[3],"age":oneData[4] 42 | }} 43 | nistdb.update(data_form) 44 | 45 | 46 | print(nistdb) 47 | 48 | 49 | 50 | 51 | 52 | 53 | if __name__ =='__main__': 54 | 55 | loading_data_from_file() -------------------------------------------------------------------------------- /16-adding_more_data.py: -------------------------------------------------------------------------------- 1 | 2 | db={} 3 | 4 | global email_exit 5 | email_exit=-1 6 | 7 | def main_sector(): 8 | main_option =int(input("Press 1 to Register:\nPress 2 to Login\nPress 3 Exit:")) 9 | if main_option== 1: 10 | registration() 11 | elif main_option==2: 12 | login() 13 | elif main_option==3: 14 | exit(1) 15 | else: 16 | print("Invalid Option") 17 | main_sector() 18 | 19 | def registration(): 20 | 21 | user_email = input("Enter your email:") 22 | email_get = Email_exit(user_email) 23 | 24 | if email_get!=None: 25 | print("Email already exit:") 26 | registration() 27 | else: 28 | user_name = input("Enter your username:") 29 | user_password = input("Enter your password:") 30 | user_phone = int(input("Enter your phone:")) 31 | user_age = int(input("Enter your age:")) 32 | 33 | id = len(db) 34 | 35 | to_insert = {id: {"email": user_email,"u_name":user_name, "password": user_password,"phone":user_phone,"age":user_age}} 36 | db.update(to_insert) 37 | 38 | 39 | def login(): 40 | user_found=-1; 41 | print("This is login sector") 42 | l_user_email = input("Enter your email to login:") 43 | l_user_password = input("Enter your password to login:") 44 | 45 | 46 | for i in range(len(db)): 47 | if db[i]["email"] == l_user_email and db[i]["password"]==l_user_password: 48 | 49 | user_found=i 50 | if user_found!=-1: 51 | print("Login Success!") 52 | user_profile(user_found) 53 | else: 54 | print("Not Found ") 55 | 56 | def user_profile(user_found): 57 | print("Welcome:",db[user_found]["u_name"]) 58 | 59 | input("Press 1 ") 60 | 61 | 62 | def Email_exit(email): 63 | 64 | lenght = len(db) 65 | for i in range(lenght): 66 | if db[i]["email"] == email: 67 | 68 | return i 69 | 70 | if __name__ == '__main__': 71 | 72 | while True: 73 | main_sector() -------------------------------------------------------------------------------- /15-completeRE.py: -------------------------------------------------------------------------------- 1 | # def adding(a,b): 2 | # c = a+b 3 | # return c 4 | # 5 | # 6 | # if __name__ == '__main__': 7 | # result =adding(1,2) 8 | # print(result) 9 | 10 | # သွားခေါ်တဲ့ function သည် return ပြန် ပေးရင် ခေါ်တဲ့ နေရာကလည်း ပြန်လက်ခံ ပေးရမယ် 11 | 12 | 13 | 14 | #test_program 15 | 16 | db={} 17 | 18 | global email_exit 19 | email_exit=-1 20 | 21 | def main_sector(): 22 | main_option =int(input("Press 1 to Register:\nPress 2 to Login\nPress 3 Exit:")) 23 | if main_option== 1: 24 | registration() 25 | elif main_option==2: 26 | login() 27 | elif main_option==3: 28 | exit(1) 29 | else: 30 | print("Invalid Option") 31 | main_sector() 32 | 33 | def registration(): 34 | 35 | user_email = input("Enter your email:") 36 | email_get = Email_exit(user_email) 37 | 38 | if email_get!=None: 39 | print("Email already exit:") 40 | registration() 41 | else: 42 | user_password = input("Enter your password:") 43 | 44 | id = len(db) 45 | 46 | to_insert = {id: {"email": user_email, "password": user_password}} 47 | db.update(to_insert) 48 | 49 | 50 | def login(): 51 | user_found=-1; 52 | print("This is login sector") 53 | l_user_email = input("Enter your email to login:") 54 | l_user_password = input("Enter your password to login:") 55 | 56 | for i in range(len(db)): 57 | if db[i]["email"] == l_user_email and db[i]["password"]==l_user_password: 58 | 59 | user_found=i 60 | if user_found!=-1: 61 | print("Login Success!") 62 | user_profile(l_user_email) 63 | else: 64 | print("Not Found ") 65 | 66 | def user_profile(info): 67 | print("Welcome:",info) 68 | 69 | 70 | def Email_exit(email): 71 | 72 | lenght = len(db) 73 | for i in range(lenght): 74 | if db[i]["email"] == email: 75 | 76 | return i 77 | 78 | if __name__ == '__main__': 79 | 80 | while True: 81 | main_sector() -------------------------------------------------------------------------------- /Dip2-Auction/server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import subprocess 3 | import os 4 | import json 5 | 6 | import pymongo 7 | 8 | connection =pymongo.MongoClient("localhost",27017) 9 | database =connection["ncc_dip2"] 10 | col =database["user_info"] 11 | 12 | 13 | class TCPserver(): 14 | def __init__(self): 15 | self.server_ip = 'localhost' 16 | self.server_port = 9998 17 | self.toSave = {} 18 | 19 | def main(self): 20 | server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 21 | server.bind((self.server_ip, self.server_port)) 22 | server.listen() 23 | print("Server listen on port:{} and ip {}".format(self.server_port, self.server_ip)) 24 | try: 25 | while True: 26 | client, address = server.accept() 27 | print("Accepted Connection from - {} : {} ".format(address[0], address[1])) 28 | self.handle_client(client) 29 | except Exception as err: 30 | print(err) 31 | 32 | def handle_client(self, client_socket): 33 | with client_socket as sock: 34 | from_client = sock.recv(1024) 35 | received_data = from_client.decode("utf-8") 36 | 37 | # output = subprocess.getoutput("dir") 38 | # # result = output.stdout.decode() 39 | # 40 | # # return_valued = os.system(received_data) 41 | 42 | 43 | 44 | if received_data=="gad": 45 | self.get_all_data(sock) 46 | 47 | 48 | def get_all_data(self,sock): 49 | data:dict ={} 50 | id=0 51 | for i in col.find({},{'_id':0}): 52 | id = len(data) 53 | dataform={"name":i["name"],"email":i["email"]} 54 | data.update({id:dataform}) 55 | 56 | str_data =json.dumps(data) 57 | 58 | str_data = bytes(str_data,'utf-8') 59 | sock.send(str_data) 60 | 61 | 62 | 63 | if __name__ == '__main__': 64 | tcpserver = TCPserver() 65 | tcpserver.main() 66 | -------------------------------------------------------------------------------- /17-data_record.py: -------------------------------------------------------------------------------- 1 | 2 | db={} 3 | 4 | global email_exit 5 | email_exit=-1 6 | 7 | def main_sector(): 8 | main_option =int(input("Press 1 to Register:\nPress 2 to Login\nPress 3 Exit:")) 9 | if main_option== 1: 10 | registration() 11 | elif main_option==2: 12 | login() 13 | elif main_option==3: 14 | exit(1) 15 | else: 16 | print("Invalid Option") 17 | main_sector() 18 | 19 | def registration(): 20 | 21 | user_email = input("Enter your email:") 22 | email_get = Email_exit(user_email) 23 | 24 | if email_get!=None: 25 | print("Email already exit:") 26 | registration() 27 | else: 28 | user_name = input("Enter your username:") 29 | user_password = input("Enter your password:") 30 | user_phone = int(input("Enter your phone:")) 31 | user_age = int(input("Enter your age:")) 32 | 33 | id = len(db) 34 | 35 | to_insert = {id: {"email": user_email,"u_name":user_name, "password": user_password,"phone":user_phone,"age":user_age}} 36 | db.update(to_insert) 37 | 38 | 39 | def login(): 40 | user_found=-1; 41 | print("This is login sector") 42 | l_user_email = input("Enter your email to login:") 43 | l_user_password = input("Enter your password to login:") 44 | 45 | 46 | for i in range(len(db)): 47 | if db[i]["email"] == l_user_email and db[i]["password"]==l_user_password: 48 | 49 | user_found=i 50 | if user_found!=-1: 51 | print("Login Success!") 52 | user_profile(user_found) 53 | else: 54 | print("Not Found ") 55 | 56 | def user_profile(user_found): 57 | print("Welcome:",db[user_found]["u_name"]) 58 | 59 | option =int(input("Press 1 to exit")) 60 | if option == 1: 61 | recording_all_data() 62 | 63 | 64 | def Email_exit(email): 65 | 66 | lenght = len(db) 67 | for i in range(lenght): 68 | if db[i]["email"] == email: 69 | 70 | return i 71 | 72 | def recording_all_data(): 73 | pass 74 | def loading_all_data(): 75 | pass 76 | 77 | if __name__ == '__main__': 78 | loading_all_data() 79 | while True: 80 | main_sector() -------------------------------------------------------------------------------- /20-recordingDataToFile.py: -------------------------------------------------------------------------------- 1 | 2 | db={} 3 | 4 | global email_exit 5 | email_exit=-1 6 | 7 | def main_sector(): 8 | main_option =int(input("Press 1 to Register:\nPress 2 to Login\nPress 3 Exit:")) 9 | if main_option== 1: 10 | registration() 11 | elif main_option==2: 12 | login() 13 | elif main_option==3: 14 | recording_all_data() 15 | exit(1) 16 | else: 17 | print("Invalid Option") 18 | main_sector() 19 | 20 | def registration(): 21 | 22 | user_email = input("Enter your email:") 23 | email_get = Email_exit(user_email) 24 | 25 | if email_get!=None: 26 | print("Email already exit:") 27 | registration() 28 | else: 29 | user_name = input("Enter your username:") 30 | user_password = input("Enter your password:") 31 | user_phone = int(input("Enter your phone:")) 32 | user_age = int(input("Enter your age:")) 33 | 34 | id = len(db) 35 | 36 | to_insert = {id: {"email": user_email,"u_name":user_name, "password": user_password,"phone":user_phone,"age":user_age}} 37 | db.update(to_insert) 38 | 39 | 40 | def login(): 41 | user_found=-1; 42 | print("This is login sector") 43 | l_user_email = input("Enter your email to login:") 44 | l_user_password = input("Enter your password to login:") 45 | 46 | 47 | for i in range(len(db)): 48 | if db[i]["email"] == l_user_email and db[i]["password"]==l_user_password: 49 | 50 | user_found=i 51 | if user_found!=-1: 52 | print("Login Success!") 53 | user_profile(user_found) 54 | else: 55 | print("Not Found ") 56 | 57 | def user_profile(user_found): 58 | print("Welcome:",db[user_found]["u_name"]) 59 | 60 | option =int(input("Press 1 to exit")) 61 | if option == 1: 62 | recording_all_data() 63 | 64 | 65 | def Email_exit(email): 66 | 67 | lenght = len(db) 68 | for i in range(lenght): 69 | if db[i]["email"] == email: 70 | 71 | return i 72 | 73 | def recording_all_data(): 74 | with open("nistdb.txt", 'w') as dbfile: 75 | for i in range(len(db)): 76 | email = db[i]["email"] 77 | user_name = db[i]["u_name"] 78 | password = db[i]["password"] 79 | phone = db[i]["phone"] 80 | age = db[i]["age"] 81 | total_user_data = email + ' ' + user_name + ' ' + password + ' ' + str(phone) + ' ' + str(age) 82 | 83 | dbfile.write(total_user_data) 84 | 85 | 86 | def loading_all_data(): 87 | with open("nistdb.txt",'r') as dbfile: 88 | datas=dbfile.readlines() 89 | for one in datas: 90 | oneData = one.split(" ") 91 | 92 | id = len(db) 93 | data_form = {id:{"email":oneData[0],"u_name":oneData[1],"password":oneData[2], 94 | "phone":oneData[3],"age":oneData[4] 95 | }} 96 | db.update(data_form) 97 | 98 | if __name__ == '__main__': 99 | loading_all_data() 100 | print(db) 101 | while True: 102 | main_sector() -------------------------------------------------------------------------------- /mongodb_py/tcp_server_mongo.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import subprocess 3 | import os 4 | import json 5 | 6 | import pymongo 7 | 8 | connection = pymongo.MongoClient("localhost", 27017) 9 | database = connection["ncc_dip2"] 10 | col = database["user_info"] 11 | 12 | candi = database["candidate"] 13 | 14 | 15 | class TCPserver(): 16 | def __init__(self): 17 | self.server_ip = 'localhost' 18 | self.server_port = 9998 19 | self.toSave = {} 20 | 21 | def main(self): 22 | server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 23 | server.bind((self.server_ip, self.server_port)) 24 | server.listen() 25 | print("Server listen on port:{} and ip {}".format(self.server_port, self.server_ip)) 26 | try: 27 | while True: 28 | client, address = server.accept() 29 | print("Accepted Connection from - {} : {} ".format(address[0], address[1])) 30 | self.handle_client(client) 31 | except Exception as err: 32 | print(err) 33 | 34 | def handle_client(self, client_socket): 35 | data_list = [] 36 | with client_socket as sock: 37 | from_client = sock.recv(1024) 38 | data_list = from_client.decode("utf-8").split(' ') # login email password 39 | 40 | # data_list = ["login","email","password"] 41 | 42 | # output = subprocess.getoutput("dir") 43 | # # result = output.stdout.decode() 44 | # 45 | # # return_valued = os.system(received_data) 46 | 47 | if data_list[0] == "gad": 48 | print("received command :", data_list[0]) 49 | self.get_all_data(sock) 50 | 51 | elif data_list[0] == "login": 52 | self.login_checking(sock, data_list) 53 | 54 | elif data_list[0] == "candidate_info": 55 | self.candidate_info(sock) 56 | 57 | elif data_list[0] == "emailcheck": 58 | 59 | self.email_checking(data_list[1], sock) 60 | 61 | 62 | elif data_list[0] == "register": 63 | 64 | self.registration(data_list, sock) 65 | 66 | 67 | else: 68 | sms = bytes("Invalid Option", "utf-8") 69 | sock.send(sms) 70 | 71 | def get_all_data(self, sock): 72 | data: dict = {} 73 | id = 0 74 | for i in col.find({}, {"_id": 0, "email": 1, "password": 1}): 75 | id = len(data) 76 | dataform = {"email": i["email"], "password": i["password"]} 77 | data.update({id: dataform}) 78 | print(data) 79 | str_data = json.dumps(data) 80 | 81 | str_data = bytes(str_data, 'utf-8') 82 | sock.send(str_data) 83 | 84 | def login_checking(self, sock, data_list): 85 | l_email = data_list[1] 86 | l_password = data_list[2] 87 | flag = -1 88 | sms = {} 89 | for i in col.find({}, {"_id": 0, "email": 1, "password": 1, "info": 1, "point": 1}): 90 | if i["email"] == l_email and i["password"] == l_password: 91 | flag = 1 92 | sms = {"email": i["email"], "info": i["info"], "point": i["point"]} 93 | sms = json.dumps(sms) 94 | 95 | break 96 | 97 | if flag == 1: 98 | str_data = bytes(sms, 'utf-8') 99 | sock.send(str_data) 100 | else: 101 | str_data = bytes("User name and password not found!", 'utf-8') 102 | sock.send(str_data) 103 | 104 | def candidate_info(self, sock): 105 | 106 | try: 107 | to_send = {} 108 | for i in candi.find({}, {"_id": 0, "name": 1, "vote_point": 1}): 109 | print(i["name"], i["vote_point"]) 110 | id = len(to_send) + 1 111 | to_update = {id: {"name": i["name"], "vote_point": i["vote_point"]}} 112 | to_send.update(to_update) 113 | 114 | to_send = json.dumps(to_send) 115 | 116 | sock.send(bytes(to_send, "utf-8")) 117 | except Exception as err: 118 | print("candiate db access err:", err) 119 | 120 | sock.send(bytes("candi_db_error", "utf-8")) 121 | 122 | def email_checking(self, email, sock): 123 | email_exist = 0 124 | for i in col.find({}, {"_id": 0, "email": 1}): 125 | if i["email"] == email: 126 | email_exist = 1 127 | 128 | if email_exist == 0: # email not already exist 129 | sock.send(bytes("notExist", "utf-8")) 130 | 131 | else: 132 | sock.send(bytes("exist", "utf-8")) 133 | 134 | def registration(self, data_list: list, sock): 135 | 136 | data_form = {"email": data_list[1], "password": data_list[2], "phone": int(data_list[3]), "info": data_list[4], 137 | "point": int(data_list[5])} 138 | 139 | ids = col.insert_one(data_form) 140 | print("Registration success for :", ids.inserted_id) 141 | 142 | sock.send(bytes(str(ids.inserted_id), "utf-8")) 143 | 144 | 145 | if __name__ == '__main__': 146 | tcpserver = TCPserver() 147 | tcpserver.main() 148 | -------------------------------------------------------------------------------- /x_Voting/voting_lib.py: -------------------------------------------------------------------------------- 1 | class Voting: 2 | def __init__(self): 3 | print("Working in Voting special method or constructor ") 4 | self.students = {0: {"name": "James", "v_mark": 0, "voter": []}, 5 | 1: {"name": "John", "v_mark": 0, "voter": []}, 6 | 2: {"name": "Rooney", "v_mark": 0, "voter": []}, 7 | 3: {"name": "Ronaldo", "v_mark": 0, "voter": []}, 8 | 4: {"name": "Messi", "v_mark": 0, "voter": []} 9 | } 10 | self.db: dict = {} 11 | self.id: int = 0 12 | 13 | self.l_id: int = 0 14 | 15 | def main_option(self): 16 | option = 0 17 | try: 18 | option = int(input("Press 1 to Register\nPress 2 to Login\nPress 3 to Exit")) 19 | except Exception as err: 20 | # print(err) 21 | print("Pls insert only Integer eg:1,2,3") 22 | 23 | if option == 1: 24 | self.register() 25 | elif option == 2: 26 | self.login() 27 | elif option == 3: 28 | exit(1) 29 | else: 30 | print("Invalid Option") 31 | self.main_option() 32 | 33 | def register(self): 34 | print("This is register option ") 35 | pass_match = False 36 | try: 37 | r_email = input("Enter your email address to register!") 38 | r_name = input("Enter your name to register!") 39 | r_phone = input("Enter your phone to register!") 40 | r_address = input("Enter your address:") 41 | 42 | while pass_match is False: 43 | r_pass1 = input("Enter your password to register!") 44 | r_pass2 = input("Retype your password:") 45 | 46 | if r_pass1 != r_pass2: 47 | print("Your passwords not match") 48 | 49 | else: 50 | print("Your passwords was recorded!") 51 | self.id = len(self.db) 52 | data_form: dict = {self.id: {"email": r_email, "name": r_name, "phone": r_phone, 53 | "address": r_address, "password": r_pass1}} 54 | 55 | self.db.update(data_form) 56 | 57 | pass_match = True 58 | except Exception as err: 59 | print("Invalid User Input!Try Again Sir!") 60 | self.register() 61 | 62 | print("Registration success :", self.db[self.id]["name"]) 63 | 64 | r_option = False 65 | while r_option is False: 66 | try: 67 | user_option = int(input("Press 1 to Login!\nPress 2 Main Option:\nPress3 to Exit!:")) 68 | if user_option == 1: 69 | self.login() 70 | break 71 | elif user_option == 2: 72 | self.main_option() 73 | break 74 | elif user_option == 3: 75 | exit(1) 76 | else: 77 | print("Pls read again for option!") 78 | 79 | except Exception as err: 80 | print("Invalid Input!", err) 81 | 82 | def login(self): 83 | print("This is login option ") 84 | length = len(self.db) 85 | try: 86 | l_email = input("Enter your email to Login:") 87 | l_pass = input("Enter your pass to Login:") 88 | self.l_id = -1 89 | for i in range(length): 90 | if l_email == self.db[i]["email"] and l_pass == self.db[i]["password"]: 91 | self.l_id = i 92 | break 93 | if self.l_id != -1: 94 | self.user_sector(self.l_id) 95 | else: 96 | print("Username or Password incorrect!") 97 | self.login() 98 | 99 | except Exception as err: 100 | print(err, "\nInvalid input:") 101 | 102 | def user_sector(self, l_id): 103 | print("Welcome", self.db[l_id]["name"]) 104 | 105 | print("Please select one!") 106 | for i in range(len(self.students)): 107 | print("Id:{} - Name {} - Current Vote Mark: {}".format(i, self.students[i]["name"], 108 | self.students[i]["v_mark"] 109 | )) 110 | 111 | try: 112 | v_id = int(input("Just Enter Id number to vote:")) 113 | 114 | self.students[v_id]["v_mark"] += 1 115 | 116 | self.students[v_id]["voter"].append(self.db[l_id]["name"]) 117 | 118 | print("Congratulation you are voted!") 119 | print("{} now voting mark is : {}".format(self.students[v_id]["name"],self.students[v_id]["v_mark"])) 120 | 121 | for i in range(len(self.students[v_id]["voter"])): 122 | print("Voter: ",self.students[v_id]["voter"][i]) 123 | 124 | 125 | except Exception as err: 126 | print(err) 127 | 128 | 129 | while True: 130 | try: 131 | vote_option = int(input("Press 1 to Vote Again!\nPress 2 to get Main Option!\nPress 3 to Force Quit:")) 132 | 133 | if vote_option == 1: 134 | self.user_sector(l_id) 135 | break 136 | elif vote_option == 2: 137 | self.main_option() 138 | break 139 | elif vote_option == 3: 140 | exit(1) 141 | else: 142 | print("Invalid option after vote!") 143 | except Exception as err: 144 | print(err) 145 | 146 | # ဆက်ရေး ရန် 8-5-2023 147 | # voter များအား စာရင်း မှတ်ပေးရန် 148 | # file ထဲ တွင် အားလုံး သိမ်းရန် 149 | # -------------------------------------------------------------------------------- /mongodb_py/tcp_client_mongo.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import json 3 | 4 | 5 | class TCPclient(): 6 | def __init__(self, sms): 7 | self.target_ip = 'localhost' 8 | self.target_port = 9998 9 | self.input_checking(sms) 10 | 11 | def client_runner(self): 12 | 13 | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 14 | client.connect((self.target_ip, self.target_port)) 15 | 16 | # client.send(self.client_sms) 17 | # 18 | # received_from_server = client.recv(4096) 19 | # 20 | # recv_sms = received_from_server.decode("utf-8") 21 | # 22 | # print("$:", recv_sms) 23 | # 24 | # client.close() 25 | return client # to send and received data 26 | 27 | def input_checking(self, sms): 28 | if sms == "gad": 29 | self.get_all_data(sms) 30 | 31 | elif sms == "login": 32 | self.login(sms) 33 | 34 | elif sms == "reg": 35 | self.register() 36 | else: 37 | print("Invalid Option") 38 | 39 | def get_all_data(self, sms): 40 | client = self.client_runner() 41 | sms = bytes(sms + ' ', "utf-8") 42 | client.send(sms) 43 | received_from_server = client.recv(4096) 44 | # print(received_from_server.decode("utf-8")) 45 | 46 | dict_data: dict = json.loads(received_from_server.decode("utf-8")) 47 | print(type(dict_data)) 48 | print(dict_data) 49 | client.close() 50 | 51 | def login(self, info): 52 | try: 53 | print("This is login Form") 54 | l_email = input("Enter your email to login:") 55 | l_pass = input("Enter your password to login:") 56 | 57 | client = self.client_runner() 58 | sms = info + ' ' + l_email + ' ' + l_pass # login email password 59 | sms = bytes(sms, "utf-8") 60 | client.send(sms) 61 | received_from_server = client.recv(4096) 62 | user_info: dict = json.loads(received_from_server.decode("utf-8")) 63 | self.option_choice(user_info, client) 64 | 65 | 66 | except Exception as err: 67 | print(err) 68 | 69 | def option_choice(self, user_info, client): 70 | print("Email :", user_info["email"]) 71 | print("Info :", user_info["info"]) 72 | print("Point :", user_info["point"]) 73 | 74 | try: 75 | option = input("Press 1 to Get User Option:\nPress 2 To Get Main Option:\nPress 3 To Exit:") 76 | if option == '1': 77 | self.user_option(user_info, client) 78 | elif option == '2': 79 | self.input_checking("from_option") # to write more option 80 | elif option == '3': 81 | exit(1) 82 | else: 83 | print("Invalid Option [X]") 84 | self.option_choice(user_info, client) 85 | 86 | except Exception as err: 87 | print(err) 88 | 89 | def user_option(self, user_info, client): 90 | try: 91 | option = input("Press 1 To Vote:\nPress 2 to get more points:\nPress 3 to Transfer Point:\n" 92 | "Press 4 To get Voting Ranking:\nPress 5 to change user information \nPress 6 to Delete Acc:\nPress 7 " 93 | "to Exit:") 94 | 95 | if option == '1': 96 | self.voting(user_info) 97 | 98 | else: 99 | print("Invalid option") 100 | self.user_option(user_info, client) 101 | 102 | except Exception as err: 103 | print(err) 104 | self.user_option(user_info, client) 105 | 106 | def voting(self, user_info): 107 | client = self.client_runner() 108 | sms = bytes("candidate_info", "utf-8") 109 | client.send(sms) 110 | 111 | info = client.recv(4096) 112 | candi_info = json.loads(info.decode("utf-8")) 113 | print(candi_info) 114 | print(type(candi_info)) 115 | for i in candi_info: 116 | print("No: ", i, "Name: ", candi_info[i]["name"], "Point", candi_info[i]["vote_point"]) 117 | 118 | client.close() 119 | 120 | def register(self): 121 | print("\nThis is registration option ") 122 | r_email = '' 123 | while True: 124 | r_email = input("Enter email for registration :") 125 | flag = self.email_checking(r_email) # 1 or -1 126 | 127 | if flag == 1: 128 | break 129 | else: 130 | print("Email Form Invalid\nTry Again! ") 131 | 132 | print("Email From Valid ") 133 | 134 | try: 135 | option = input("Press 1 Registration for Voter:\nPress 2 Registration for Candidate!:") 136 | 137 | if option == '1': 138 | self.reg_for_voter(r_email) 139 | elif option == '2': 140 | pass 141 | 142 | else: 143 | self.register() 144 | except Exception as err: 145 | print(err) 146 | 147 | def email_checking(self, r_email): 148 | name_counter = 0 149 | for i in range(len(r_email)): 150 | if r_email[i] == '@': 151 | # print("Name End Here") 152 | break 153 | name_counter += 1 154 | 155 | print("Name counter: ", name_counter) 156 | 157 | email_name = r_email[0:name_counter] 158 | email_form = r_email[name_counter:] 159 | 160 | # print(email_name) 161 | print(email_form) 162 | 163 | # checking for name 164 | name_flag = 0 165 | email_flag = 0 166 | for i in range(len(email_name)): 167 | aChar = email_name[i] 168 | if (ord(aChar) > 31 and ord(aChar) < 48) or (ord(aChar) > 57 and ord(aChar) < 65) or ( 169 | ord(aChar) > 90 and ord(aChar) < 97) or (ord(aChar) > 122 and ord(aChar) < 128): 170 | name_flag = -1 171 | break 172 | 173 | domain_form = ["@facebook.com", "@ncc.com", "@mail.ru", "@yahoo.com", "@outlook.com", "@apple.com", "@zoho.com", 174 | "@gmail.com"] 175 | 176 | for i in range(len(domain_form)): 177 | 178 | if domain_form[i] == email_form: 179 | email_flag = 1 180 | break 181 | 182 | if name_flag == -1 or email_flag == 0: 183 | return -1 184 | 185 | else: 186 | return 1 187 | 188 | def reg_for_voter(self, r_email): 189 | 190 | if self.email_check_inDB(r_email): 191 | try: 192 | pass1 = input("Enter your password to register:") 193 | pass2 = input("Enter your password Again to register:") 194 | 195 | if pass1 == pass2: 196 | 197 | print("Password Was match!") 198 | phone = int(input("Enter your phone number:")) 199 | 200 | data_list = [r_email, pass1, phone] 201 | self.final_registration(data_list) 202 | 203 | else: 204 | print("Password not match:") 205 | self.reg_for_voter(r_email) 206 | 207 | 208 | except Exception as err: 209 | print(err) 210 | 211 | else: 212 | 213 | print("Your email was already register!") 214 | self.register() 215 | 216 | def email_check_inDB(self, email): 217 | 218 | client = self.client_runner() 219 | data = "emailcheck" + " " + email 220 | 221 | client.send(bytes(data, "utf-8")) 222 | 223 | received = client.recv(4096).decode("utf-8") 224 | 225 | print(received) 226 | 227 | if received == "notExist": 228 | client.close() 229 | return True 230 | else: 231 | client.close() 232 | return False 233 | 234 | def final_registration(self, data_list): 235 | 236 | data_form = "register" + " " + data_list[0] + " " + data_list[1] + " " + str( 237 | data_list[2]) + " " + "User" + " " + "100" 238 | 239 | client = self.client_runner() 240 | 241 | client.send(bytes(data_form, "utf-8")) 242 | 243 | recv = client.recv(4096).decode("utf-8") 244 | 245 | print(recv) 246 | 247 | if recv: 248 | print("Registration Success!",recv) 249 | info="login" 250 | self.login(info) 251 | 252 | client.close() 253 | 254 | 255 | if __name__ == "__main__": 256 | while True: 257 | sms = input("Enter some data to send:") 258 | tcp_client = TCPclient(sms) 259 | --------------------------------------------------------------------------------