2018-05-24 12:57:38 +02:00
|
|
|
#Used for scraping osu version names from osu.ppy.sh and storing them into self database
|
|
|
|
|
2018-05-29 10:46:42 +02:00
|
|
|
import json
|
2018-05-24 12:57:38 +02:00
|
|
|
import MySQLdb
|
|
|
|
import MySQLdb.cursors
|
2018-05-29 08:03:48 +02:00
|
|
|
import time, calendar, string
|
2018-05-24 12:57:38 +02:00
|
|
|
import atexit
|
|
|
|
|
2018-05-29 10:46:42 +02:00
|
|
|
# Because ppy site is dumb
|
|
|
|
import requests
|
|
|
|
|
2018-05-24 12:57:38 +02:00
|
|
|
with open("config.json", "r") as f:
|
|
|
|
config = json.load(f)
|
|
|
|
|
|
|
|
with open("memory.json", "r") as f:
|
|
|
|
memory = json.load(f)
|
|
|
|
|
|
|
|
sql = MySQLdb.connect(**config["sql"], cursorclass = MySQLdb.cursors.DictCursor)
|
|
|
|
|
|
|
|
cur = sql.cursor()
|
|
|
|
|
|
|
|
def on_close():
|
|
|
|
with open("memory.json", "w") as f:
|
|
|
|
json.dump(memory, f)
|
|
|
|
print("Closing...")
|
|
|
|
|
|
|
|
atexit.register(on_close)
|
|
|
|
|
2018-05-29 08:03:48 +02:00
|
|
|
#---------------------------------------
|
2018-05-24 12:57:38 +02:00
|
|
|
|
2018-05-29 10:46:42 +02:00
|
|
|
SCAN = "_" + string.printable[:62] + "-+.:,"
|
|
|
|
NAMES = []
|
2018-05-29 08:03:48 +02:00
|
|
|
|
|
|
|
def check(s):
|
2018-05-29 10:46:42 +02:00
|
|
|
o = requests.get("https://osu.ppy.sh/web/get-internal-version.php?v={}".format(s))
|
|
|
|
i = int(o.content.decode())
|
|
|
|
return i
|
|
|
|
|
|
|
|
def scan_line(s):
|
|
|
|
global NAMES
|
|
|
|
data = {
|
|
|
|
"scan": [],
|
|
|
|
"items": 0
|
|
|
|
}
|
|
|
|
items_found = 0
|
|
|
|
current_string = s + "_"
|
|
|
|
for i in range(1, len(SCAN)):
|
|
|
|
r = check(current_string)
|
|
|
|
|
|
|
|
if current_string.endswith("_"):
|
|
|
|
data["items"] = r
|
|
|
|
if r is 0: # We hit the end! Add it to the entries list
|
|
|
|
c = current_string[:-1]
|
|
|
|
print("FOUND: {}".format(c))
|
|
|
|
cur.execute("INSERT INTO osu_builds (id,version) VALUES (NULL,%s)", [ c ])
|
|
|
|
sql.commit()
|
|
|
|
NAMES.append(c)
|
|
|
|
break
|
|
|
|
elif r > 0: # This is not the length scan and an entry was found so... we add it :D
|
|
|
|
print("Pending branch: {} ({} found)".format(current_string, r))
|
|
|
|
data["scan"].append(current_string)
|
|
|
|
items_found += r
|
|
|
|
|
|
|
|
if items_found >= data["items"]: # We have all the entries for this branch
|
|
|
|
print("Found all items in branch: {} ({} found)".format(current_string[:-1], items_found))
|
|
|
|
break
|
|
|
|
|
|
|
|
current_string = current_string[:-1] + SCAN[i]
|
|
|
|
return data
|
|
|
|
|
|
|
|
def branch(s):
|
|
|
|
scan_data = scan_line(s)
|
|
|
|
for item in scan_data["scan"]:
|
|
|
|
branch(item)
|
|
|
|
|
|
|
|
branch("") # LEL INIT
|
|
|
|
|
|
|
|
for entry in NAMES:
|
|
|
|
print(entry)
|
|
|
|
|
|
|
|
print("DONE!")
|