Last active
September 20, 2017 06:52
-
-
Save simform-solutions/9f5e383569af28174a9e624cc3c9f3a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will try to open the account file. In case the file doesn't exist it will create a new account file. | |
def read_account_data(): | |
try: | |
with open(file_name, 'r') as account_data: | |
data = json.load(account_data) | |
return data | |
except: | |
with open(file_name, 'w') as account_data: | |
data = {} | |
data['account_data'] = [] | |
data['account_data'].append({ | |
'settings': [{'host': "Enter iota node uri with port", 'min_weight_magnitude': 15, 'units': "i"}], | |
'address_data': [], | |
'fal_balance': [{'f_index': 0, 'l_index': 0}], | |
'transfers_data': [] | |
}) | |
json.dump(data, account_data) | |
print("Created new account file!") | |
return data | |
# Converts Iotas into the unit that is set in the account settings and returns a string | |
def convert_units(value): | |
unit = settings[0]['units'] | |
value = float(value) | |
if unit == "i": | |
value = str(int(value)) + "i" | |
return value | |
elif unit == "ki": | |
value = '{0:.3f}'.format(value/1000) | |
value = str(value + "Ki") | |
return value | |
elif unit == "mi": | |
value = '{0:.6f}'.format(value / 1000000) | |
value = str(value) + "Mi" | |
return value | |
elif unit == "gi": | |
value = '{0:.9f}'.format(value / 1000000000) | |
value = str(value + "Gi") | |
return value | |
elif unit == "ti": | |
value = '{0:.12f}'.format(value / 1000000000000) | |
value = str(value + "Ti") | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment