Skip to content
Snippets Groups Projects
Commit d683205c authored by Pál Boldizsár's avatar Pál Boldizsár
Browse files

problematic save and load

parent e8b395fa
Branches
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ez file lenne ami osszekoti a db-t a programunkal. hogy egyszerubb legyen ...@@ -3,7 +3,7 @@ ez file lenne ami osszekoti a db-t a programunkal. hogy egyszerubb legyen
az eletunk, ezert most csak egyszeru dictekbe, meg setekbe tarolunk mindent az eletunk, ezert most csak egyszeru dictekbe, meg setekbe tarolunk mindent
""" """
# import pprint # import pprint
import re
fake_db = {} fake_db = {}
# ez garantalja hogy egy username csak egyszer lehet benne # ez garantalja hogy egy username csak egyszer lehet benne
fake_db['u_names'] = set() fake_db['u_names'] = set()
...@@ -11,6 +11,25 @@ fake_db['u_names'] = set() ...@@ -11,6 +11,25 @@ fake_db['u_names'] = set()
fake_db['users'] = [] fake_db['users'] = []
def load_db():
try:
with open('db.txt', 'r') as f:
data = f.readline()
m = re.search('username (.*) - password (.*)', data)
while data != '':
m = re.search('username (.*) - password (.*)', data)
assert m.group()
if m.group(1) in fake_db['u_names']:
data = f.readline(1)
continue
fake_db['users'].append({'Username': m.group(1), 'Password': m.group(2)})
fake_db['u_names'].add(m.group(1))
data = f.readline(1)
except OSError as e:
return 'Succes'
return 'Succes'
def check_user_name(username=None): def check_user_name(username=None):
if not username: if not username:
return 'No name given' return 'No name given'
......
...@@ -16,6 +16,7 @@ def login_user(username=None, password=None): ...@@ -16,6 +16,7 @@ def login_user(username=None, password=None):
if __name__ == "__main__": if __name__ == "__main__":
print(db.load_db())
while 1: while 1:
text_input = input("Press enter to start registration, anything else \ text_input = input("Press enter to start registration, anything else \
+ enter if login") + enter if login")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment