-
-
Save jleclanche/9421666 to your computer and use it in GitHub Desktop.
Style improvements etc
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
#!/usr/bin/env python | |
import json | |
import sys | |
try: | |
from urllib.request import urlopen | |
except ImportError: | |
from urllib2 import urlopen | |
input = raw_input | |
REGION = "us" | |
HOST = "http://%s.battle.net" % (REGION) | |
QUESTS = { | |
"act1": [ | |
"The Fallen Star", | |
"The Legacy of Cain", | |
"A Shattered Crown", | |
"Reign of the Black King", | |
"Sword of the Stranger", | |
"The Broken Blade", | |
"The Doom in Wortham", | |
"Trailing the Coven", | |
"The Imprisoned Angel", | |
"Return to New Tristram", | |
], | |
} | |
def loadJSON(url): | |
response = urlopen(url).read().decode("utf-8") | |
return json.loads(response) | |
def getChars(bnet): | |
url = HOST + "/api/d3/profile/%s/" % (bnet) | |
json_profile = loadJSON(url) | |
characters = [] | |
for char in json_profile["heroes"]: | |
characters.append(char["id"]) | |
return characters | |
def checkQuests(bnet, characters): | |
act1 = QUESTS["act1"] | |
for character in characters: | |
url = HOST + "/api/d3/profile/%s/hero/%s" % (bnet, character) | |
json_char = loadJSON(url) | |
if len(json_char["progress"]["normal"]["act1"]["completedQuests"]) < 10 and json_char["level"] == 60: | |
print("{0} - {1} - Level {2}".format(json_char["name"], json_char["class"], json_char["level"])) | |
completed = [] | |
for quest in json_char["progress"]["normal"]["act1"]["completedQuests"]: | |
completed.append(str(quest["name"])) | |
missing = set(act1) - set(completed) | |
for q in missing: | |
print(q) | |
def main(): | |
import sys | |
if len(sys.argv) > 1: | |
bnet = sys.argv[1] | |
else: | |
bnet = input("Enter your Bnet ID, ex. Name#1234: ") | |
bnet = bnet.replace("#", "-") | |
checkQuests(bnet, getChars(bnet)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment