forked from Fragrance/maquitous
feat: add bonus function
This commit is contained in:
96
main.py
96
main.py
@@ -12,11 +12,14 @@ from ticket import get_ticket
|
||||
from charge import charge
|
||||
from map import map
|
||||
from userdata import userdata
|
||||
from mapstock import music_with_retry as mapstock
|
||||
from character import character
|
||||
|
||||
from sdgb import sdgb_api
|
||||
from mapstock import music_with_retry as mapstock
|
||||
from music import music_with_retry as music
|
||||
from unlock_all import music_with_retry as unlock
|
||||
from map_clear import music_with_retry as map_clear
|
||||
from bonus9 import music_with_retry as login_bonus
|
||||
|
||||
def find_map(mapId, user_map_data):
|
||||
for single in user_map_data:
|
||||
@@ -57,6 +60,68 @@ def item(item_data, user_character_list):
|
||||
return item_list, character_list, item_data[-1]['distance']
|
||||
|
||||
|
||||
def bonus_list_gen(userId):
|
||||
with open('login_bonus.json') as file:
|
||||
cache = json.load(file)
|
||||
bonus_data = []
|
||||
for item in cache:
|
||||
bonus_data.append(item['id'])
|
||||
cache = []
|
||||
data = json.dumps({
|
||||
"userId": int(userId),
|
||||
"nextIndex":0,
|
||||
"maxCount":2000
|
||||
})
|
||||
user_bonus = json.loads(sdgb_api(data, "GetUserLoginBonusApi", userId))['userLoginBonusList']
|
||||
for item in user_bonus:
|
||||
cache.append(item['bonusId'])
|
||||
bonus_list_unexist = list(set(bonus_data) - set(cache))
|
||||
bonus_list = []
|
||||
for item in user_bonus:
|
||||
if item['isComplete'] == False:
|
||||
if item['bonusId'] in [12, 29, 30, 38, 43, 604]:
|
||||
data = ({
|
||||
"bonusId": item['bonusId'],
|
||||
"point": 4,
|
||||
"isCurrent": item['isCurrent'],
|
||||
"isComplete": False
|
||||
})
|
||||
else:
|
||||
data = ({
|
||||
"bonusId": item['bonusId'],
|
||||
"point": 9,
|
||||
"isCurrent": item['isCurrent'],
|
||||
"isComplete": False
|
||||
})
|
||||
bonus_list.append(data)
|
||||
elif item['bonusId'] == 999:
|
||||
data = ({
|
||||
"bonusId": 999,
|
||||
"point": item['point'] // 10 * 10 + 9,
|
||||
"isCurrent": item['isCurrent'],
|
||||
"isComplete": False
|
||||
})
|
||||
bonus_list.append(data)
|
||||
else:
|
||||
pass
|
||||
for item in bonus_list_unexist:
|
||||
if item in [12, 29, 30, 38, 43, 604]:
|
||||
data = ({
|
||||
"bonusId": item,
|
||||
"point": 4,
|
||||
"isCurrent": False,
|
||||
"isComplete": False
|
||||
})
|
||||
else:
|
||||
data = ({
|
||||
"bonusId": item,
|
||||
"point": 9,
|
||||
"isCurrent": False,
|
||||
"isComplete": False
|
||||
})
|
||||
bonus_list.append(data)
|
||||
return bonus_list
|
||||
|
||||
app = Flask(__name__)
|
||||
app.json.sort_keys = False
|
||||
app.json.ensure_ascii = False
|
||||
@@ -311,5 +376,34 @@ def maps():
|
||||
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "map", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
|
||||
return data, returnCode
|
||||
|
||||
@app.route("/bonus")
|
||||
def bonus():
|
||||
userId = request.args.get('userid')
|
||||
if userId is None or userId.isdigit() is False or len(str(userId)) != 8:
|
||||
return jsonify({"apiName": "bonus", "apiInfo": "Get 9 Stamps in Login Bonus Items.", "apiUsage": "/bonus?userid=<userId>"})
|
||||
else:
|
||||
userId = int(userId)
|
||||
timestamp = int(time.time())
|
||||
login_data = login(userId, timestamp)
|
||||
if login_data['returnCode'] == 102:
|
||||
returnCode = 403
|
||||
status = "403 Forbidden"
|
||||
info = "Unable to operate. Please refresh QrCode."
|
||||
log = {}
|
||||
elif login_data['returnCode'] == 100:
|
||||
returnCode = 403
|
||||
status = "403 Forbidden"
|
||||
info = "Unable to operate. Probably User has logged in."
|
||||
log = {}
|
||||
elif login_data['returnCode'] == 1:
|
||||
logout(userId, timestamp)
|
||||
login_bonus(userId, bonus_list_gen(userId))
|
||||
returnCode = 200
|
||||
status = "200 OK"
|
||||
info = "Succeed."
|
||||
log = {"UserLoginApiStatus": 1, "UploadUserPlaylogApiStatus": 1, "UpsertUserAllApi": 1, "UserLogoutApiStatus": 1}
|
||||
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "unlock", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
|
||||
return data, returnCode
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port = 8080)
|
||||
|
||||
Reference in New Issue
Block a user