305 lines
14 KiB
Python
305 lines
14 KiB
Python
import time
|
|
import json
|
|
import pytz
|
|
from datetime import datetime
|
|
from flask import Flask,request,redirect,jsonify
|
|
from flask_cors import CORS
|
|
|
|
from logout import logout
|
|
from login import login
|
|
from process import *
|
|
|
|
from sdgb import sdgb_api, felica
|
|
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
|
|
|
|
app = Flask(__name__)
|
|
app.json.sort_keys = False
|
|
app.json.ensure_ascii = False
|
|
app.json.mimetype = 'application/json;charset=UTF-8'
|
|
app.json.compact = False
|
|
CORS(app)
|
|
|
|
@app.errorhandler(404)
|
|
def page_not_found(e):
|
|
return jsonify({"status": "404 Not Found", "timestamp": int(time.time()), "info": "The route you are trying to access is missing.", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')}), 404
|
|
|
|
@app.errorhandler(405)
|
|
def method_not_allowed(e):
|
|
return jsonify({"status": "405 Method Not Allowed", "timestamp": int(time.time()), "info": "You are using the wrong method. Check the docs.", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')}), 405
|
|
|
|
@app.errorhandler(400)
|
|
def bad_request(e):
|
|
return jsonify({"status": "400 Bad Request", "timestamp": int(time.time()), "info": "Something went Wrong.", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')}), 400
|
|
|
|
@app.errorhandler(500)
|
|
def bad_request(e):
|
|
return jsonify({"status": "500 Internal Server Error", "timestamp": int(time.time()), "info": "Something went Wrong.", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')}), 500
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return jsonify({"status": "200 OK", "timestamp": int(time.time()), "info": "Sennoza - Project Fragrance","availableApi": ["felica", "ticket", "mapstock", "unlock", "music", "map", "bonus"], "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')}), 200
|
|
|
|
@app.route("/felica")
|
|
def felica_lookup():
|
|
IDm = request.args.get('idm')
|
|
if IDm is None or len(str(IDm)) != 16:
|
|
return jsonify({"apiName": "felica", "apiInfo": "Activate Your Amusement IC Card", "apiUsage": "/felica?idm=<IDm>"})
|
|
else:
|
|
info = felica(IDm)
|
|
if info == "00000000000000000000":
|
|
returnCode = 404
|
|
status = "404 Not Found"
|
|
info = "Your IDm is invalid"
|
|
else:
|
|
returnCode = 200
|
|
status = "200 OK"
|
|
data = jsonify({"status": status, "timestamp": int(time.time()), "info": info, "apiName": "felica", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8')})
|
|
return data, returnCode
|
|
|
|
@app.route("/ticket")
|
|
def ticket():
|
|
IDm = request.args.get('idm')
|
|
if IDm is None or len(str(IDm)) != 16:
|
|
return jsonify({"apiName": "ticket", "apiInfo": "Send x6 Ticket", "apiUsage": "/ticket?idm=<IDm>"})
|
|
else:
|
|
userId = aimedb_userId(IDm)[0]
|
|
accessCode = aimedb_userId(IDm)[1]
|
|
timestamp = int(time.time())
|
|
if '{"chargeId": 6, "stock": 1' in json.dumps(charge(userId)):
|
|
returnCode = 403
|
|
status = "403 Forbidden"
|
|
info = "User has had a ticket."
|
|
log = {}
|
|
else:
|
|
login_data = login(userId, accessCode, 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:
|
|
ticket_data = get_ticket(userId)
|
|
if ticket_data['returnCode'] == 0:
|
|
logout(userId, accessCode, timestamp)
|
|
returnCode = 403
|
|
status = "403 Forbidden"
|
|
info = "WARNING: THIS INFO SHOULD NEVER APPEARS. IF YOU SEE THIS WARNING PLEASE CONTACT Telegram@sasakure. Unable to operate. Successfully Logged in. Probably User has had one ticket."
|
|
log = {"UserLoginApiStatus": 1, "UserLogoutApiStatus": 1}
|
|
elif ticket_data['returnCode'] == 1:
|
|
logout(userId, accessCode, timestamp)
|
|
returnCode = 200
|
|
status = "200 OK"
|
|
info = "Succeed."
|
|
log = {"UserLoginApiStatus": 1, "UpsertUserChargelogStatus": 1, "UserLogoutApiStatus": 1}
|
|
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "ticket", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
|
|
return data, returnCode
|
|
|
|
@app.route("/mapstock")
|
|
def mapstock_process():
|
|
userId = request.args.get('userid')
|
|
if userId is None or userId.isdigit() is False or len(str(userId)) != 8:
|
|
return jsonify({"apiName": "mapstock", "apiInfo": "Save 99 Kilometers in Maps.", "apiUsage": "/mapstock?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:
|
|
userdata_result = userdata(userId)
|
|
logout(userId, timestamp)
|
|
if userdata_result['userData']['mapStock'] == 99000:
|
|
returnCode = 403
|
|
status = "403 Forbidden"
|
|
info = "User has stocked 99 kilometers."
|
|
log = {}
|
|
else:
|
|
while True:
|
|
login(userId, timestamp)
|
|
userdata_result = userdata(userId)
|
|
logout(userId, timestamp)
|
|
if userdata_result['userData']['mapStock'] == 99000:
|
|
returnCode = 200
|
|
status = "200 OK"
|
|
info = "Succeed."
|
|
log = {"UserLoginApiStatus": 1, "UploadUserPlaylogApiStatus": 1, "UpsertUserAllApi": 1, "UserLogoutApiStatus": 1}
|
|
break
|
|
else:
|
|
mapstock(userId)
|
|
continue
|
|
else:
|
|
returnCode = 500
|
|
status = "500 Internal Server Error"
|
|
info = "Unknown Error. Failed in UserLogin"
|
|
log = login_data
|
|
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "mapstock", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
|
|
return data, returnCode
|
|
|
|
@app.route("/unlock")
|
|
def unlock_process():
|
|
IDm = request.args.get('idm')
|
|
if IDm is None or len(str(IDm)) != 16:
|
|
return jsonify({"apiName": "unlock", "apiInfo": "Unlock All DX Master Charts.", "apiUsage": "/unlock?idm=<IDm>"})
|
|
else:
|
|
userId = aimedb_userId(IDm)[0]
|
|
accessCode = aimedb_userId(IDm)[1]
|
|
timestamp = int(time.time())
|
|
login_data = login(userId, accessCode, 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:
|
|
userdata_result = userdata(userId)
|
|
logout(userId, accessCode, timestamp)
|
|
unlock(userId, accessCode)
|
|
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
|
|
|
|
@app.route("/music", methods=['POST'])
|
|
def music_post():
|
|
request_data = request.get_json()
|
|
if 'IDm' in request_data and 'music' in request_data:
|
|
if request_data['IDm'] is None or len(str(request_data['IDm'])) != 16:
|
|
return jsonify({"apiName": "music", "apiInfo": "Overwrite Music Data in UserData.", "apiUsage": ""})
|
|
else:
|
|
IDm = request_data['IDm']
|
|
userId = aimedb_userId(IDm)[0]
|
|
accessCode = aimedb_userId(IDm)[1]
|
|
timestamp = int(time.time())
|
|
login_data = login(userId, accessCode, 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, accessCode, timestamp)
|
|
music_data = request_data['music']
|
|
music(userId, accessCode, music_data)
|
|
returnCode = 200
|
|
status = "200 OK"
|
|
info = "Succeed."
|
|
log = {"UserLoginApiStatus": 1, "UploadUserPlaylogApiStatus": 1, "UpsertUserAllApi": 1,"UserLogoutApiStatus": 1}
|
|
else:
|
|
returnCode = 500
|
|
status = "500 Internal Server Error"
|
|
info = "Unknown Error. Failed in UserLogin"
|
|
log = login_data
|
|
else:
|
|
return jsonify({"apiName": "music", "apiInfo": "Overwrite Music Data in UserData.", "apiUsage": ""})
|
|
data = jsonify({"status": status, "timestamp": timestamp, "info": info, "apiName": "music", "date": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%a, %d %b %Y %H:%M:%S GMT+8'), "userId": userId})
|
|
return data, returnCode
|
|
|
|
@app.route("/map")
|
|
def maps():
|
|
with open('map.json') as file:
|
|
map_data = json.load(file)
|
|
available = [{"mapId": entry["mapId"], "name": entry["name"]} for entry in map_data]
|
|
mapId = request.args.get('mapid')
|
|
IDm = request.args.get('idm')
|
|
if IDm is None or len(str(IDm)) != 16 or mapId is None or mapId.isdigit() is False:
|
|
return jsonify({"apiName": "map", "apiInfo": "Complete Map", "apiUsage": "/map?userid=<userId>&mapid=<mapId>", "availableMaps": available})
|
|
else:
|
|
userId = aimedb_userId(IDm)[0]
|
|
accessCode = aimedb_userId(IDm)[1]
|
|
mapId = int(mapId)
|
|
user_map_data = json.dumps(map(userId)['userMapList'])
|
|
#return user_map_data
|
|
item_data = find_map(mapId, map_data)['treasure']
|
|
user_character_list = json.dumps(character(userId)['userCharacterList'])
|
|
item_list = item(item_data, user_character_list)[0]
|
|
character_list = item(item_data, user_character_list)[1]
|
|
distance = item(item_data, user_character_list)[2]
|
|
timestamp = int(time.time())
|
|
login_data = login(userId, accessCode, 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, accessCode, timestamp)
|
|
map_clear(userId, accessCode, mapId, distance, item_list, character_list, isNewMapList(mapId, user_map_data))
|
|
returnCode = 200
|
|
status = "200 OK"
|
|
info = "Succeed."
|
|
log = {"UserLoginApiStatus": 1, "UploadUserPlaylogApiStatus": 1, "UpsertUserAllApi": 1, "UserLogoutApiStatus": 1}
|
|
else:
|
|
returnCode = 500
|
|
status = "500 Internal Server Error"
|
|
info = "Unknown Error. Failed in UserLogin"
|
|
log = login_data
|
|
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 = 8081)
|