Separates handling of ussd and user json data in the users export dir tree.
This commit is contained in:
parent
a9a04d3caa
commit
c75c2ec630
@ -63,23 +63,28 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
for x in os.walk(user_old_dir):
|
for x in os.walk(user_old_dir):
|
||||||
for y in x[2]:
|
for y in x[2]:
|
||||||
|
# skip non-json files
|
||||||
if y[len(y) - 5:] != '.json':
|
if y[len(y) - 5:] != '.json':
|
||||||
continue
|
continue
|
||||||
filepath = os.path.join(x[0], y)
|
|
||||||
f = open(filepath, 'r')
|
# define file path for
|
||||||
try:
|
filepath = None
|
||||||
o = json.load(f)
|
if y != 'ussd_data.json':
|
||||||
except json.decoder.JSONDecodeError as e:
|
filepath = os.path.join(x[0], y)
|
||||||
|
f = open(filepath, 'r')
|
||||||
|
try:
|
||||||
|
o = json.load(f)
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
f.close()
|
||||||
|
logg.error('load error for {}: {}'.format(y, e))
|
||||||
|
continue
|
||||||
f.close()
|
f.close()
|
||||||
logg.error('load error for {}: {}'.format(y, e))
|
u = Person.deserialize(o)
|
||||||
continue
|
|
||||||
f.close()
|
|
||||||
u = Person.deserialize(o)
|
|
||||||
|
|
||||||
phone_object = phonenumbers.parse(u.tel)
|
phone_object = phonenumbers.parse(u.tel)
|
||||||
phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
|
phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
|
||||||
password_hash = generate_password_hash()
|
password_hash = generate_password_hash()
|
||||||
pins_file.write(f'{phone},{password_hash}\n')
|
pins_file.write(f'{phone},{password_hash}\n')
|
||||||
logg.debug(f'Writing phone: {phone}, password_hash: {password_hash}')
|
logg.info(f'Writing phone: {phone}, password_hash: {password_hash}')
|
||||||
|
|
||||||
pins_file.close()
|
pins_file.close()
|
||||||
|
@ -130,6 +130,7 @@ def genCats():
|
|||||||
def genAmount():
|
def genAmount():
|
||||||
return random.randint(0, gift_max) * gift_factor
|
return random.randint(0, gift_max) * gift_factor
|
||||||
|
|
||||||
|
|
||||||
def genDob():
|
def genDob():
|
||||||
dob_src = fake.date_of_birth(minimum_age=15)
|
dob_src = fake.date_of_birth(minimum_age=15)
|
||||||
dob = {}
|
dob = {}
|
||||||
@ -168,8 +169,9 @@ def gen():
|
|||||||
}
|
}
|
||||||
p.location['area_name'] = city
|
p.location['area_name'] = city
|
||||||
if random.randint(0, 1):
|
if random.randint(0, 1):
|
||||||
p.identities['latitude'] = (random.random() + 180) - 90 #fake.local_latitude()
|
p.location['latitude'] = (random.random() + 180) - 90 #fake.local_latitude()
|
||||||
p.identities['longitude'] = (random.random() + 360) - 180 #fake.local_latitude()
|
p.location['longitude'] = (random.random() + 360) - 180 #fake.local_latitude()
|
||||||
|
|
||||||
|
|
||||||
return (old_blockchain_checksum_address, phone, p)
|
return (old_blockchain_checksum_address, phone, p)
|
||||||
|
|
||||||
@ -215,6 +217,20 @@ if __name__ == '__main__':
|
|||||||
json.dump(o.serialize(), f)
|
json.dump(o.serialize(), f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# create ussd data
|
||||||
|
ussd_data_dir = os.path.join(d, 'ussd_data')
|
||||||
|
os.makedirs(ussd_data_dir)
|
||||||
|
f = open('{}/{}/{}'.format(d, 'ussd_data', 'ussd_data.json'), 'w')
|
||||||
|
ussd_data = {
|
||||||
|
'phone': phone,
|
||||||
|
'is_activated': 1,
|
||||||
|
'preferred_language': random.sample(['en', 'sw'], 1)[0],
|
||||||
|
'is_disabled': False
|
||||||
|
}
|
||||||
|
json.dump(ussd_data, f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
pidx = genPhoneIndex(phone)
|
pidx = genPhoneIndex(phone)
|
||||||
d = prepareLocalFilePath(os.path.join(user_dir, 'phone'), pidx)
|
d = prepareLocalFilePath(os.path.join(user_dir, 'phone'), pidx)
|
||||||
f = open('{}/{}'.format(d, pidx), 'w')
|
f = open('{}/{}'.format(d, pidx), 'w')
|
||||||
|
Loading…
Reference in New Issue
Block a user