Skip to content

Commit

Permalink
add time out retry function
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Oct 15, 2023
1 parent 6a5f82d commit 807c5b4
Showing 1 changed file with 58 additions and 26 deletions.
84 changes: 58 additions & 26 deletions method.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import base64
from Crypto.Cipher import AES
from Crypto.Util import Padding
import io
import struct

import zipfile
import requests

from collections import OrderedDict
from requests.adapters import HTTPAdapter
from Crypto.Cipher import AES

from Crypto.Util import Padding


levels = ["EZ", "HD", "IN", "AT"]
Expand Down Expand Up @@ -195,12 +199,19 @@ def get_playerId(sessionToken):

@staticmethod
def get_summary(sessionToken):
headers = global_headers.copy()
headers["X-LC-Session"] = sessionToken
response = requests.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
)
try:
s = requests.session()
s.mount("http://", HTTPAdapter(max_retries=3))
s.mount("https://", HTTPAdapter(max_retries=3))
headers = global_headers.copy()
headers["X-LC-Session"] = sessionToken
response = s.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
timeout=5,
)
except Exception as e:
return None, "Network error."
result = response.json()["results"][0]
updateAt = result["updatedAt"]
url = result["gameFile"]["url"]
Expand All @@ -222,12 +233,19 @@ def get_summary(sessionToken):

@staticmethod
def get_formatData(sessionToken):
headers = global_headers.copy()
headers["X-LC-Session"] = sessionToken
response = requests.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
)
try:
s = requests.session()
s.mount("http://", HTTPAdapter(max_retries=3))
s.mount("https://", HTTPAdapter(max_retries=3))
headers = global_headers.copy()
headers["X-LC-Session"] = sessionToken
response = s.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
timeout=5,
)
except Exception as e:
return None, "Network error."
result = response.json()["results"][0]
summary = base64.b64decode(result["summary"])
get_id = BestsRender.get_playerId(sessionToken)
Expand All @@ -240,25 +258,39 @@ def get_formatData(sessionToken):

@staticmethod
def get_bests(session, overflow):
headers = global_headers.copy()
headers["X-LC-Session"] = session
response = requests.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
)
try:
s = requests.session()
s.mount("http://", HTTPAdapter(max_retries=3))
s.mount("https://", HTTPAdapter(max_retries=3))
headers = global_headers.copy()
headers["X-LC-Session"] = session
response = s.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
timeout=5,
)
except Exception as e:
return None, "Network error."
result = response.json()["results"][0]["gameFile"]["url"]
gameRecord = DataPackage.GameReader(result)
gameRecord = decrypt_gameRecord(gameRecord)
return parse_render_bests(gameRecord, overflow)

@staticmethod
def get_songs_stats(session, songid, diff):
headers = global_headers.copy()
headers["X-LC-Session"] = session
response = requests.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
)
try:
s = requests.session()
s.mount("http://", HTTPAdapter(max_retries=3))
s.mount("https://", HTTPAdapter(max_retries=3))
headers = global_headers.copy()
headers["X-LC-Session"] = session
response = s.get(
"https://rak3ffdi.cloud.tds1.tapapis.cn/1.1/classes/_GameSave",
headers=headers,
timeout=5,
)
except Exception as e:
return None, "Network error."
result = response.json()["results"][0]["gameFile"]["url"]
if result == None:
return None, "No Game Record"
Expand Down

0 comments on commit 807c5b4

Please sign in to comment.