-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (83 loc) · 3.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import webapp2
import requests
import requests_toolbelt.adapters.appengine
import json
import urllib
from google.appengine.api import urlfetch
urlfetch.set_default_fetch_deadline(15)
from flask import Flask, request
app = Flask(__name__)
requests_toolbelt.adapters.appengine.monkeypatch()
import platform
class MainPage(webapp2.RequestHandler):
@app.route("/chars/<data>")
def chars(data):
headers = {"X-API-Key": "<API Key>"}
getMember = requests.get("https://www.bungie.net/Platform/User/GetMembershipsById/" + data + "/0/", headers = headers)
memberJSON = getMember.json()
for member in memberJSON["Response"]["destinyMemberships"]:
if(member["membershipType"] == 4):
membershipId = member["membershipId"]
break
getChars = requests.get("https://www.bungie.net/Platform/Destiny2/4/Profile/" + membershipId + "?components=Characters", headers = headers)
charsJSON = json.loads(getChars.text)
return (json.dumps(charsJSON))
@app.route("/login/<data>")
def login(data):
authCode = data
b64 = 'Basic <Base 64 encoded client_id:client_secret>'
HEADERS = {'Content-Type': 'application/x-www-form-urlencoded;', 'Authorization': b64}
post_data = {'grant_type': 'authorization_code', 'code': authCode}
response = requests.post("https://www.bungie.net/Platform/App/OAuth/Token/", data=post_data, headers=HEADERS)
loginJSON = json.loads(response.text)
info = response.json()
global access_token
access_token = urllib.unquote(info["access_token"])
print(access_token)
global memberId
memberId = info["membership_id"]
return(json.dumps(loginJSON))
@app.route("/getequipped/")
def getequipped():
global access_token
headers = {"X-API-Key": "<API Key>", 'Authorization': 'Bearer ' + access_token}
getMember = requests.get("https://www.bungie.net/Platform/User/GetMembershipsForCurrentUser/", headers = headers)
print(getMember)
memberJSON = getMember.json()
return(json.dumps(memberJSON))
@app.route("/token/<path:path>")
def token(path):
print("IN /TOKEN")
global access_token
access_token = urllib.unquote(path)
print("ACCESS 1: " + access_token)
return "200"
@app.route("/getchar/<type>/<id>")
def getchar(type, id):
# manifestmain()
# getinfo(identifier, value)
print("TYPE: " + type)
print("ID: " + id)
headers = {"X-API-Key": "<API Key>", 'Authorization': 'Bearer ' + access_token}
getCharInfo = requests.get("https://www.bungie.net/Platform/Destiny2/" + type + "/Profile/" + id + "/?components=CharacterEquipment,CharacterInventories", headers = headers)
itemsJSON = json.loads(getCharInfo.text)
# itemsJSON = getCharInfo.json()
return (json.dumps(itemsJSON["Response"]))
charsItems = itemJSON["Response"]["characterEquipment"]["data"]
return json.dumps(charsItems)
@app.route("/getitemdata/<type>/<hash>")
def getitemdata(type, hash):
headers = {"X-API-Key": "<API Key>"}
response = requests.get("http://www.bungie.net/Platform/Destiny2/Manifest/" + type + "/" + hash + "/", headers=headers)
rJSON = response.json()
return(json.dumps(rJSON))
@app.route("/equipitem/<item>/<char>/<membertype>")
def equipitem(item, char, membertype):
print("IN EQUIP " + item + " " + char + " " + membertype)
HEADERS = {"X-API-Key": "<API Key>", 'Authorization': 'Bearer ' + access_token}
post_data = json.dumps({'itemId': item, 'characterId': char, 'membershipType': membertype})
response = requests.post("https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItem/", headers = HEADERS, data = post_data)
equipJSON = json.loads(response.text)
return(json.dumps(equipJSON))
if __name__ == "__main__":
app.run()