wallet.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # GPL3 or any later version
  2. import os
  3. import json
  4. def save_folder(fold="jyt/"):
  5. # gets the save / settings folder
  6. try:
  7. data_dir = os.environ["XDG_DATA_HOME"] + "/" + fold
  8. except:
  9. data_dir = os.path.expanduser("~/.local/share/"+fold)
  10. try:
  11. os.makedirs(data_dir)
  12. except:
  13. pass
  14. return data_dir
  15. def get_list():
  16. # gets list of the wallets
  17. folder = save_folder()+"wallets/"
  18. try:
  19. os.makedirs(folder)
  20. except:
  21. pass
  22. wallets = list(os.walk(folder))[0][1]
  23. wallets = sorted(wallets)
  24. return wallets
  25. def get_totals(the_wallet):
  26. # returns wallet data
  27. try:
  28. with open(save_folder()+"wallets/"+the_wallet+"/totals.json") as json_file:
  29. data = json.load(json_file)
  30. except Exception as e:
  31. data = {}
  32. return data
  33. def save_totals(the_wallet, data):
  34. print("saving")
  35. with open(save_folder()+"wallets/"+the_wallet+"/totals.json", "w") as fp:
  36. json.dump(data, fp, indent=4)