Skip to content

Commit

Permalink
Merge pull request #65 from NebraLtd/parse-fixer
Browse files Browse the repository at this point in the history
Fixes parsing from latest GA release
  • Loading branch information
vpetersson authored Aug 20, 2021
2 parents 250e025 + cc55b38 commit a418ee7
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions config-python/config_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,33 @@

# Public Onboarding Keys
while True:
try:
public_keys_file = open("/var/data/public_keys").readline().split('"')
break
except FileNotFoundError:
logging.debug('Waiting for keyfile')
sleep(60)

# Keyfile exists, now running.
pubKey = str(public_keys_file[1])
onboardingKey = str(public_keys_file[3])
animalName = str(public_keys_file[5])
if os.path.isfile('/var/data/public_keys'):
public_keys = {}
with open("/var/data/public_keys") as f:
for line in f.readlines():
# This is insanely ugly, but it gets the
# job done until we switch to the API
erlang_to_json = line.replace('.', '').\
replace(',', ': ').\
replace('pubkey', '"pubkey"').\
replace('onboarding_key', '"onboarding_key"').\
replace('animal_name', '"animal_name"')

# Let's future proof this just
# in case something changes later
try:
json_line = json.loads(erlang_to_json)
for key in json_line.keys():
public_keys[key] = json_line[key]
except json.JSONDecodeError:
pass

pubKey = public_keys.get('pubkey', False)
onboardingKey = public_keys.get('onboarding_key', False)
animalName = public_keys.get('animal_name', False)
else:
print('File public key file not found. Going to sleep')
sleep(60)

# Setup Thread Variables
advertisementLED = False
Expand Down

0 comments on commit a418ee7

Please sign in to comment.