Improved error handling

This commit is contained in:
Bofh 2021-02-07 02:59:14 +01:00
parent ece785b02e
commit d11a739593
1 changed files with 8 additions and 8 deletions

View File

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