· 4 years ago · Mar 22, 2021, 03:36 AM
1import http.client, base64
2import json
3import urllib
4from urllib import request, parse, error
5from PyQt5 import QtCore, QtGui, QtWidgets, uic
6from PyQt5.QtWidgets import QDialog
7from PyQt5.uic import loadUi
8import requests
9import sys
10
11
12headers = {
13 # Request headers
14 'Ocp-Apim-Subscription-Key': '{apikey}',}
15players = ['Xenkuru'] #Replace with user input
16params = urllib.parse.urlencode({
17 # Request parameters
18 'seasonId': '{string}',
19})
20
21f = open("api_key.txt", "r")
22if(f.read()) == "":
23 print("yes")
24else:
25 print("Fetched API Key!")
26
27
28class MainWindow(QDialog):
29 def __init__(self):
30 super(MainWindow, self).__init__()
31 uic.loadUi("desgin.ui", self)
32
33class tools(QDialog):
34 def __init__(self):
35 super(MainWindow, self).__init__()
36 uic.loadUi("desgin.ui", self)
37
38
39 def gamertagWebPuller(self):
40 gt = self.gamertag.text()
41 gt = gt.replace(' ', '%20')
42 try:
43 conn = http.client.HTTPSConnection('www.haloapi.com')
44 conn.request("GET", "/stats/h5/servicerecords/arena?players=%s&%s" % (gt, params), "{body}", headers)
45 response = conn.getresponse()
46 data = response.read()
47 json_data = json.loads(data)
48
49 currentXP = (json_data["Results"][0]["Result"]["Xp"])
50 print(currentXP)
51
52 #NEXT STEP: Turn "data" into a json then read a specific element from it
53 conn.close()
54 except Exception as e:
55 print(e)
56
57
58
59
60 def retranslateUi(self, MainWindow):
61 _translate = QtCore.QCoreApplication.translate
62 MainWindow.setWindowTitle(_translate("MainWindow", "Halo 5 Stat Tracker"))
63 self.gamertag.setPlaceholderText(_translate("MainWindow", "Api Key"))
64 self.launchButton.setText(_translate("MainWindow", "Launch"))
65 self.launchButton.clicked.connect(self.gamertagWebPuller)
66 self.introduction.setText(_translate("MainWindow", "In order for this program to work you need an API Key.\n"
67 "To get and API Key head over to https://developer.haloapi.com to \n"
68 "sign up for the free API Key.\n"
69 "This key will be stored locally and will only be sent to \n"
70 "https://developer.haloapi.com"))
71
72
73
74if __name__ == "__main__":
75 app = QtWidgets.QApplication(sys.argv)
76 ui = MainWindow()
77 ui.setupUi(MainWindow)
78 MainWindow.show()
79 sys.exit(app.exec_())
80