The resolve_thing_name() method is responsible for loading or creating a unique name for our thing for use with dweet.io.
Our intention when using this method is to always reuse a name so that our dweet URLs for controlling our LED remain the same between the program restarts:
def resolve_thing_name(thing_file):
"""Get existing, or create a new thing name"""
if os.path.exists(thing_file): # (3)
with open(thing_file, 'r') as file_handle:
name = file_handle.read()
logger.info('Thing name ' + name +
' loaded from ' + thing_file)
return name.strip()
else:
name = str(uuid1())[:8] # (4)
logger.info('Created new thing name ' + name)
with open(thing_file, 'w') as f: # (5)
f.write(name)
return name
On line...