Skip to content

Commit

Permalink
loads tier list and pick rates from web, updated constantly
Browse files Browse the repository at this point in the history
  • Loading branch information
eoakley committed Dec 8, 2018
1 parent 5b7970e commit 232a59b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
# C extensions
*.so

settings.txt
screenshot_debugg.png
make_installer.txt
custom_grid.npy
Expand Down
28 changes: 18 additions & 10 deletions artifact_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -63,19 +72,18 @@ 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',
'launcher_y':'default'

}
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:
Expand Down Expand Up @@ -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:

Expand All @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
25 changes: 19 additions & 6 deletions tier_list_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@ 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()
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
return tier_dict

0 comments on commit 232a59b

Please sign in to comment.