forked from bismoy2013/InstaStat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.py
44 lines (33 loc) · 1.13 KB
/
storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from conf import storage,user_log
import json
import uuid
class Storage(object):
data = {}
def reload(self):
with open(storage,'r') as f:
self.data = json.loads(f.read())
def __init__(self):
self.reload()
def remove(self):
pass
def add(self, key, value):
self.data[key] = value
with open(storage,'w') as f:
json.dump(self.data, f, indent=4, sort_keys=True)
f.write('\n')
self.reload()
def get(self, key, default=False):
return self.data.get(key, default)
def put(self, access_token):
cookie = str(uuid.uuid4())
self.add(key=cookie, value=access_token)
return cookie
def put2(self,access_token,user_info):
with open(user_log,'r') as f:
info = json.loads(f.read())
user_info['token'] = access_token
info[user_info['username']] = user_info
with open(user_log,'w') as f:
#f.write("%s : %s : %s \n" % (user_info['username'],user_info['full_name'],access_token))
json.dump(info,f,indent=4,sort_keys=True)
f.write('\n')