forked from aarronc/hutton-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanonnevents.py
160 lines (129 loc) · 4.41 KB
/
canonnevents.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import threading
import requests
import sys
import json
try:
# for Python2
from Tkinter import Frame
import Tkinter as tk
from urllib import quote_plus
except ImportError:
# for python 3
import tkinter as tk
from urllib.parse import quote_plus
from tkinter import Frame
class whiteListGetter(threading.Thread):
def __init__(self,callback):
threading.Thread.__init__(self)
self.callback=callback
def run(self):
#debug("getting whiteList")
url="https://us-central1-canonn-api-236217.cloudfunctions.net/whitelist"
r=requests.get(url)
if not r.status_code == requests.codes.ok:
print("whiteListGetter {} ".format(url))
print(r.status_code)
print(r.json())
results=[]
else:
results=r.json()
self.callback(results)
class whiteListSetter(threading.Thread):
def __init__(self,cmdr, is_beta, system, station, entry, state,x,y,z,body,lat,lon,client):
threading.Thread.__init__(self)
self.cmdr=cmdr
self.system=system
self.is_beta=is_beta
self.station=station
self.body=body
self.entry=entry
self.state=state
self.x=x
self.y=y
self.z=z
self.lat=state.get("Latitude")
self.lon=state.get("Longitude")
self.client=client
self.odyssey=state.get("Odyssey")
def run(self):
url="https://us-central1-canonn-api-236217.cloudfunctions.net/postEvent"
#url="http://192.168.0.72:8080"
data = {
"gameState": {
"systemName": self.system,
"systemCoordinates": [self.x, self.y, self.z],
"bodyName": self.body,
"station": self.station,
"latitude": self.lat,
"longitude": self.lon,
"clientVersion": self.client,
"isBeta": self.is_beta,
"platform": "PC",
"odyssey": self.odyssey
},
"rawEvent": self.entry,
"eventType": self.entry.get("event"),
"cmdrName": self.cmdr
}
r = requests.post(url, data=json.dumps(data, ensure_ascii=False).encode('utf8'),
headers={"content-type": "application/json"})
if not r.status_code == requests.codes.ok:
print("whiteListSetter {} ".format(url))
print(r.status_code)
#print(r.json())
results=[]
else:
try:
#results=r.json()
print(r)
except Exception as e:
print(e)
'''
Going to declare this aa a frame so I can run a time
'''
class whiteList(Frame):
whitelist = []
systems={}
def __init__(self, parent):
Frame.__init__(
self,
parent
)
'''
if all the keys match then return true
'''
@classmethod
def matchkeys(cls,event,entry):
ev=json.loads(event)
for key in ev.keys():
if not entry.get(key) == ev.get(key):
return False
return True
@classmethod
def journal_entry(cls,cmdr, is_beta, system, station, entry, state,client):
try:
#cache the the star positions
if entry.get("StarSystem") and entry.get("StarPos"):
print("HH caching star")
print(entry.get("StarPos"))
cls.systems[entry.get("StarSystem")]=entry.get("StarPos")
for event in whiteList.whitelist:
if cls.matchkeys(event.get("definition"),entry) and system:
if cls.systems.get(system):
print("HH Getting star")
print(cls.systems.get(system))
x,y,z=cls.systems.get(system)
else:
x,y,z=(None,None,None)
print("whiteListSetter")
whiteListSetter(cmdr, is_beta, system, station, entry, state,x,y,z,state.get("Body"),None,None,client).start()
except Exception as e:
print(e)
'''
We will fetch the whitelist on the hour
'''
def fetchData(self):
whiteListGetter(self.whiteListCallback).start()
self.after(1000*60*60*24,self.fetchData)
def whiteListCallback(self,data):
whiteList.whitelist=data