From 232a59b13e812452f52f54993f978731ee10b443 Mon Sep 17 00:00:00 2001 From: "DESKTOP-2H16E6M\\Eric" Date: Sat, 8 Dec 2018 13:11:28 -0200 Subject: [PATCH] loads tier list and pick rates from web, updated constantly --- .gitignore | 1 + artifact_helper.py | 28 ++++++++++++++++++---------- tier_list_scrape.py | 25 +++++++++++++++++++------ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index ec62eb1..e69f4c2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ __pycache__/ # C extensions *.so +settings.txt screenshot_debugg.png make_installer.txt custom_grid.npy diff --git a/artifact_helper.py b/artifact_helper.py index 518859b..846ec5e 100644 --- a/artifact_helper.py +++ b/artifact_helper.py @@ -15,7 +15,7 @@ from PIL import Image, ImageTk from mss import mss import atexit - +from urllib.request import urlopen path_root = os.path.dirname(sys.modules['__main__'].__file__) def path(filename): @@ -29,6 +29,15 @@ def OpenUrl(opt=''): webbrowser.open_new('https://github.com/eoakley/artifacthelper') def load_pickle(file_name="card_dict.pkl"): + if 'http' in file_name: + #load pickle from web + try: + s = urlopen(file_name).read() + return pickle.loads(s) + except Exception as err: + print("Error loading pickle") + print(err) + try: with open(file_name, 'rb') as handle: b = pickle.load(handle) @@ -46,7 +55,7 @@ def save_settings(settings,filename="settings.txt"): line = str(k)+" = "+str(v)+"\n" text += line - with open(filename, "w") as text_file: + with open(path(filename), "w") as text_file: text_file.write(text) return True @@ -63,7 +72,6 @@ def load_settings(filename="settings.txt"): 'show_win_rate' : True, 'show_pick_rate' : True, 'show_price' : True, - 'flag_auto_scan':False, 'overlay_x':0, 'overlay_y':0, 'launcher_x':'default', @@ -71,11 +79,11 @@ def load_settings(filename="settings.txt"): } try: - if os.path.exists(filename) ==False: + if os.path.exists(path(filename)) ==False: print("Saving settings for the first time..") save_settings(settings,filename=filename) else: - with open(filename, "r") as ins: + with open(path(filename), "r") as ins: for line in ins: if (line.startswith("#")==False) and ("=" in line): if len(line.split('=')) == 2: @@ -113,9 +121,10 @@ def fix_dict(d): executor = ThreadPoolExecutor(40) -stats = fix_dict(load_pickle(path('resources/card_dict.pkl'))) +#loads tier list and pick rates from web, updated constantly +stats = fix_dict(load_pickle('https://raw.githubusercontent.com/eoakley/artifactscraping/master/card_dict.pkl')) -tiers = fix_dict(read_tier_text(path('tier_list.txt'))) +tiers = fix_dict(read_tier_text(urlopen('https://raw.githubusercontent.com/eoakley/artifactscraping/master/tier_list.txt').read(), raw=True)) #tiers got updated, poor fix for now: @@ -131,13 +140,12 @@ def fix_dict(d): launcher_x, launcher_y = settings['launcher_x'], settings['launcher_y'] overlay_x, overlay_y = settings['overlay_x'], settings['overlay_y'] -flag_auto_scan = settings['flag_auto_scan'] x_drag, y_drag = None, None flag_auto_hide = False - +flag_auto_scan = False bg_color = 'magenta' @@ -550,7 +558,7 @@ def swap_window(root, screen_width, screen_height, first_time=False): def save_settings_on_exit(): print("Saving and closing") - global settings, overlay_x,overlay_y + global settings, overlay_x, overlay_y settings['overlay_x'] = overlay_x settings['overlay_y'] = overlay_x save_settings(settings) diff --git a/tier_list_scrape.py b/tier_list_scrape.py index 20a5395..32da6b7 100644 --- a/tier_list_scrape.py +++ b/tier_list_scrape.py @@ -14,11 +14,24 @@ def __repr__(self): def __str__(self): return self.tier + ' (' + self.tier_rank + ') ' + self.custom -def read_tier_text(filename="tier_list.txt"): +def read_tier_text(filename="tier_list.txt", raw=False): tier_dict = {} - with open(filename, "r") as ins: - for line in ins: - if line.startswith("#")==False: + if not raw: + with open(filename, "r") as ins: + for line in ins: + if line.startswith("#")==False: + props = line.split(";") + name = props[0].strip() + tier = props[1].strip() + tier_rank = props[2].strip() + custom = props[3].rstrip("\n") + card = Tier_List_Card(name,tier,tier_rank=tier_rank,custom=custom) + tier_dict[name] = card + + return tier_dict + if raw: + for line in filename.decode().split('\n'): + if line.startswith("#")==False and len(line)>0: props = line.split(";") name = props[0].strip() tier = props[1].strip() @@ -26,5 +39,5 @@ def read_tier_text(filename="tier_list.txt"): custom = props[3].rstrip("\n") card = Tier_List_Card(name,tier,tier_rank=tier_rank,custom=custom) tier_dict[name] = card - - return tier_dict \ No newline at end of file + + return tier_dict