Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. try:
  2.     with open("database.json", "r+") as datahere:
  3.         db = json.load(datahere)
  4.  
  5.  
  6. except:
  7.     print("Database file not found / corrupted!")
  8.  
  9.  
  10.  
  11. def jsondump(update):
  12.     new_user_id = update.message.from_user.id
  13.     try:
  14.         if new_user_id not in db:
  15.             user = {
  16.                 "%r" % new_user_id:
  17.                     [
  18.                         {"NAME": ""},
  19.                         {"AGE": 00},
  20.                         {"BIO": ""},
  21.                         {"INTERESTS": []},
  22.                         {"PICTURE_PATH": ""}
  23.  
  24.                     ]
  25.             }
  26.  
  27.             with open("database.json", "r+") as dataload:
  28.                 data = json.load(dataload)
  29.  
  30.             data.update(user)
  31.  
  32.             with open("database.json", "r+") as datadump:
  33.                 json.dump(data, datadump, indent=4)
  34.     except:
  35.         print("Json data write failed!")
  36.  
  37. def test(bot, update):
  38.     id1 = str(update.message.from_user.id)
  39.     test2 = db[id1][NAME] = "HELL" # this doesn't stick in the file at all
  40.     json.dump(test2, db)
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. --------------------------------FILE--------------------------------------------
  48.  
  49. {
  50.     "91495773": [
  51.         {
  52.             "NAME": ""
  53.         },
  54.         {
  55.             "AGE": 0
  56.         },
  57.         {
  58.             "BIO": ""
  59.         },
  60.         {
  61.             "INTERESTS": []
  62.         },
  63.         {
  64.             "PICTURE_PATH": ""
  65.         }
  66.     ]
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement