user data storing
This commit is contained in:
23
bot.py
23
bot.py
@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
# necessary modules
|
# necessary modules
|
||||||
import os, time, requests, telepot
|
import os, time, json, requests, telepot
|
||||||
from telepot.loop import MessageLoop
|
from telepot.loop import MessageLoop
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
# kCOJ API
|
# kCOJ API
|
||||||
@ -138,8 +138,29 @@ def on_chat(msg):
|
|||||||
else:
|
else:
|
||||||
user.send_answer('', msg['document']['file_id'])
|
user.send_answer('', msg['document']['file_id'])
|
||||||
|
|
||||||
|
# restore
|
||||||
|
with open('users.json', 'r') as f:
|
||||||
|
users_restore = json.load(f)
|
||||||
|
for key in users_restore.keys():
|
||||||
|
user = users_restore[key]
|
||||||
|
users[key] = kuser(user['userid'], user['username'], user['password'], user['status'], user['question'])
|
||||||
|
|
||||||
MessageLoop(bot, on_chat).run_as_thread()
|
MessageLoop(bot, on_chat).run_as_thread()
|
||||||
print("Started! Service is available.")
|
print("Started! Service is available.")
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
bot.getMe()
|
bot.getMe()
|
||||||
|
|
||||||
|
# backup
|
||||||
|
users_backup = {}
|
||||||
|
for key in users.keys():
|
||||||
|
user = users[key]
|
||||||
|
users_backup[key] = {
|
||||||
|
'userid': user.userid,
|
||||||
|
'username': user.username,
|
||||||
|
'password': user.password,
|
||||||
|
'status': user.status,
|
||||||
|
'question': user.question
|
||||||
|
}
|
||||||
|
with open('users.json', 'w') as f:
|
||||||
|
json.dump(users_backup, f)
|
1
users.json
Normal file
1
users.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
Reference in New Issue
Block a user