-
-
Save reactormonk/6dd8372d5b3391d4ba8203e818c1b853 to your computer and use it in GitHub Desktop.
This file contains 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
# From your application settings | |
client_id = | |
client_secret = | |
redirect_uri = | |
# When you're fleet boss, copy fleet link in the dropdown. | |
fleet_url = | |
from oauthlib.oauth2 import BackendApplicationClient | |
from requests_oauthlib import OAuth2Session | |
import re | |
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope = "fleetRead fleetWrite", auto_refresh_url="https://login.eveonline.com/oauth/token") | |
authorization_url, state = oauth.authorization_url("https://login.eveonline.com/oauth/authorize") | |
print('Please go to %s and authorize access.' % authorization_url) | |
auth_response = input("Please copy/paste the callback url.\n") | |
import os | |
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" | |
token = oauth.fetch_token("https://login.eveonline.com/oauth/token", client_secret=client_secret, authorization_response=auth_response) | |
fleet = oauth.get(fleet_url).json() | |
def find_hrefs(node): | |
try: | |
gen = node.items() | |
except AttributeError: | |
gen = enumerate(node) | |
for key, item in gen: | |
if isinstance(item, dict) or isinstance(item, list): | |
yield from find_hrefs(item) | |
else: | |
if key == "href": | |
yield item | |
already_visited = set() | |
def walk(json): | |
for href in find_hrefs(json): | |
id = re.sub("[0-9]", "", href) | |
if id not in already_visited and href.find("https://crest-tq.eveonline.com/") != -1: | |
already_visited.add(id) | |
resp = oauth.get(href) | |
if resp.status_code == 400: | |
yield resp | |
elif resp.status_code == 200: | |
yield from walk(resp.json()) | |
for failed in walk(fleet): | |
print("The call to " + failed.url + " failed with " + failed.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment