Finished version_scrape script

This commit is contained in:
Emily 2018-05-29 10:46:42 +02:00
parent 92ab017689
commit 3e9a7d05d7

View File

@ -1,11 +1,14 @@
#Used for scraping osu version names from osu.ppy.sh and storing them into self database #Used for scraping osu version names from osu.ppy.sh and storing them into self database
import urllib.request, json import json
import MySQLdb import MySQLdb
import MySQLdb.cursors import MySQLdb.cursors
import time, calendar, string import time, calendar, string
import atexit import atexit
# Because ppy site is dumb
import requests
with open("config.json", "r") as f: with open("config.json", "r") as f:
config = json.load(f) config = json.load(f)
@ -25,69 +28,54 @@ atexit.register(on_close)
#--------------------------------------- #---------------------------------------
VERSIONS = check("_") # Gets all versions SCAN = "_" + string.printable[:62] + "-+.:,"
BRANCH = { NAMES = []
"_": VERSIONS
}
SCAN = string.printable[:62] + "-+.:,"
def check(s): def check(s):
return urllib.request.urlopen("https://osu.ppy.sh/web/get-internal-version.php?v={}".format(s)).read().decode() 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):
TMP = "" global NAMES
def scope(v): data = {
global TMP "scan": [],
TMP = "" "items": 0
o_key = "" }
o_value = v["_"] items_found = 0
v = _scope(v) current_string = s + "_"
print(v) for i in range(1, len(SCAN)):
print(TMP) r = check(current_string)
print(o_key)
print(o_value)
def _scope(v): if current_string.endswith("_"):
global TMP data["items"] = r
for key, value in v.items(): if r is 0: # We hit the end! Add it to the entries list
if type(value) is int: c = current_string[:-1]
if len(v) is 1: print("FOUND: {}".format(c))
return key cur.execute("INSERT INTO osu_builds (id,version) VALUES (NULL,%s)", [ c ])
continue sql.commit()
TMP += key NAMES.append(c)
return _scope(v[key]) 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
return {o_key: o_value} 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
OUT = "" current_string = current_string[:-1] + SCAN[i]
ENTRIES = v["_"] return data
for key, value in v.items():
if key is "_":
continue
elif type(value) is int:
return key
else:
S = scope(v[key])
OUT += key + S.keys()[0]
ENTRIES = S.values()[0]
return {OUT: ENTRIES}
"""
char_index = 0 def branch(s):
current_string = "_" scan_data = scan_line(s)
while memory["version_scrape"]["last"] < VERSIONS: for item in scan_data["scan"]:
branch(item)
""" branch("") # LEL INIT
s = scope(BRANCH) for entry in NAMES:
if s.endswith("_"): # Branch into? print(entry)
entries = BRANCH[s]
if entries is 0: print("DONE!")
continue # Meh... we are at the end
else:
"""
#r = check()