forked from seeebek/EliteOCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eddnexport.py
71 lines (63 loc) · 2.4 KB
/
eddnexport.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
import requests
import json
import time
from PyQt4.QtCore import QThread, SIGNAL
class EDDNExport(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.parent = parent
def execute(self, data, userID):
self.data = data
self.userID = userID
self.start()
def run(self):
parent = self.parent
data = self.data
userID = self.userID
#print data
outcomeok = []
outcomefail = []
toprocess = len(data)
counter = 0
for line in data:
try:
postdata = json.dumps(self.createRequest(line, userID))
r = requests.post("http://eddn-gateway.elite-markets.net:8080/upload/", data=postdata)
#print postdata
#time.sleep(1)
if r.text.strip() == "OK":
outcomeok.append("OK")
else:
print(line[2] + " failed")
outcomefail.append("Fail")
except:
outcomefail.append("Fail")
print(line[2] + " failed")
#pass
counter += 1
self.emit(SIGNAL("update(int,int)"), counter, toprocess)
self.result = "Success: "+str(len(outcomeok))+" Fail: "+str(len(outcomefail))
self.emit(SIGNAL("finished(QString)"), self.result)
def createRequest(self, line, userID):
request = {
"$schemaRef": "http://schemas.elite-markets.net/eddn/commodity/1",
"header": {
"uploaderID": userID,
"softwareName": "EliteOCR",
"softwareVersion": self.parent.appversion
},
"message": self.makeDict(line)
}
return request
def makeDict(self, line):
new_dict = { "systemName": line[0],
"stationName": line[1],
"itemName": line[2],
"buyPrice": (int(line[4]) if line[4] else 0),
"stationStock": (int(line[7]) if line[7] else 0),
"sellPrice": (int(line[3]) if line[3] else 0),
"demand": (int(line[5]) if line[5] else 0),
"timestamp": line[9],
}
#print new_dict
return new_dict