Improved error handling 2

This commit is contained in:
Bofh 2021-02-07 03:01:57 +01:00
parent d11a739593
commit 47a72b57d6
1 changed files with 7 additions and 2 deletions

View File

@ -10,7 +10,11 @@ import re
def add_igaccount(acc_id):
accfile = './db/accounts/{}'.format(acc_id)
if not os.path.exists(accfile) and os.path.exists('./scripts/user_create'):
if not os.path.exists('./scripts/user_create'):
print('E| You may need to initialize the server environment first')
return 1
if not os.path.exists(accfile):
data = getig_user_data(acc_id)
name = data['graphql']['user']['full_name']
name = re.sub(r'[^a-zA-Z0-9_\s]', '', name)
@ -25,7 +29,8 @@ def add_igaccount(acc_id):
w.write(json.dumps(account))
w.close()
else:
print('E| You may need to initialize the server environment first')
print('W| User "{}" already exists in local database'.format(acc_id))
return 0
def random_string(count=32):
return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=count))