Last active
February 7, 2017 20:30
-
-
Save orlp/82258f864e30e55e8036492fa67dc9f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard, Hardcore, tmpstandard, tmphardcore | |
league = "tmpstandard" | |
categories = [ | |
"DivinationCards", | |
"Essence", | |
"UniqueMap", | |
"UniqueFlask", | |
"UniqueWeapon", | |
"UniqueArmour", | |
"UniqueMap", | |
# These aren't very useful as almost all drop as same base: | |
# "UniqueAccessory", | |
# "UniqueJewel", | |
] | |
filters = [ | |
(0.95, """ | |
SetTextColor 255 0 255 | |
PlayAlertSound 4 300 | |
SetFontSize 42 | |
"""), | |
(10, """ | |
SetTextColor 255 0 255 | |
PlayAlertSound 1 300 | |
SetFontSize 42 | |
SetBorderColor 255 0 0 | |
"""), | |
] | |
exceptions = ["Silverbranch"] | |
import json, collections | |
from urllib.request import urlopen | |
API_URL = "http://poeninja.azureedge.net/api/Data/Get{}Overview?league={}" | |
Item = collections.namedtuple("Item", ["name", "cval", "base", "klass"]) | |
def get_poeninja_data(category, league): | |
conn = urlopen(API_URL.format(category, league)) | |
data = json.loads(conn.read().decode("utf-8")) | |
klass = {"DivinationCards": "Divination Card", "Essence": "Currency"}.get(category, None) | |
return [Item(item["name"], item["chaosValue"], item["baseType"], klass) | |
for item in data["lines"]] | |
items = [] | |
for category in categories: | |
items += get_poeninja_data(category, league) | |
# import pickle | |
# with open("item.txt", "wb") as f: | |
# pickle.dump(items, f) | |
# import pickle | |
# with open("item.txt", "rb") as f: | |
# items = pickle.load(f) | |
def is_ascii(s): | |
try: | |
s.encode("ascii") | |
return True | |
except UnicodeEncodeError: | |
return False | |
# Item filters can't handle unicode. | |
items = [i for i in items if is_ascii(i.base or "")] | |
items = [i for i in items if i.name not in exceptions] | |
def quote(name): | |
if " " in name: return '"' + name + '"' | |
return name | |
for min_cval, aesthetics in sorted(filters, reverse=True): | |
remaining, fitems = [], [] | |
for i in items: | |
[remaining, fitems][i.cval >= min_cval].append(i) | |
items = remaining | |
byclass = collections.defaultdict(list) | |
for i in fitems: byclass[i.klass].append(i) | |
block_lines = [l.strip() for l in aesthetics.strip().split("\n")] | |
for klass, kitems in byclass.items(): | |
names = [quote(i.klass != "Currency" and i.base or i.name) for i in kitems] | |
classblock_lines = block_lines[:] | |
classblock_lines += ["BaseType " + " ".join(names)] | |
if klass: classblock_lines += ["Class " + klass] | |
else: classblock_lines += ["Rarity Unique"] | |
print("Show\n" + "\n".join(" " + l for l in classblock_lines)) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment