-
Notifications
You must be signed in to change notification settings - Fork 0
/
first-transactions.py
157 lines (114 loc) · 4.64 KB
/
first-transactions.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
'''
Created on 10 Jan 2016
@author: adam
'''
from __future__ import print_function
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import object
import eveapi
import time
import tempfile
import pickle
import zlib
import os
from os.path import join, exists
from eveSQL import firstGo
#Row(name:Flicky G,characterID:859818750,corporationName:Flicky G Corporation,corporationID:98436502,allianceID:0,allianceName:,factionID:0,factionName:)
#'EVE API Stuff
CHAR_KEYID = 4958524
CHAR_VCODE = "njXdwQdNFNlf47TfOAnbNuHP6gX7sJeArgD2AEk1Qpay1tkUagUMyStSriZPQqd0"
CHAR_AMASK = 1073741823
#Corp
CORP_KEYID = 1383071
CORP_VCODE = "m0ecx5e1r8RCMsizNKXyB91HQchkHjJmNJlG8or0xy3VvkpiAJj1J7wXb70lUMm0"
CORP_AMASK = 268435455
eveapi.set_user_agent("eveapi.py/1.3")
api = eveapi.EVEAPIConnection()
class MyCacheHandler(object):
# Note: this is an example handler to demonstrate how to use them.
# a -real- handler should probably be thread-safe and handle errors
# properly (and perhaps use a better hashing scheme).
def __init__(self, debug=False):
self.debug = debug
self.count = 0
self.cache = {}
self.tempdir = join(tempfile.gettempdir(), "eveapi")
if not exists(self.tempdir):
os.makedirs(self.tempdir)
def log(self, what):
if self.debug:
print("[%d] %s" % (self.count, what))
def retrieve(self, host, path, params):
# eveapi asks if we have this request cached
key = hash((host, path, frozenset(list(params.items()))))
self.count += 1 # for logging
# see if we have the requested page cached...
cached = self.cache.get(key, None)
if cached:
cacheFile = None
#print "'%s': retrieving from memory" % path
else:
# it wasn't cached in memory, but it might be on disk.
cacheFile = join(self.tempdir, str(key) + ".cache")
if exists(cacheFile):
self.log("%s: retrieving from disk" % path)
f = open(cacheFile, "rb")
cached = self.cache[key] = pickle.loads(zlib.decompress(f.read()))
f.close()
if cached:
# check if the cached doc is fresh enough
if time.time() < cached[0]:
self.log("%s: returning cached document" % path)
return cached[1] # return the cached XML doc
# it's stale. purge it.
self.log("%s: cache expired, purging!" % path)
del self.cache[key]
if cacheFile:
os.remove(cacheFile)
self.log("%s: not cached, fetching from server..." % path)
# we didn't get a cache hit so return None to indicate that the data
# should be requested from the server.
return None
def store(self, host, path, params, doc, obj):
# eveapi is asking us to cache an item
key = hash((host, path, frozenset(list(params.items()))))
cachedFor = obj.cachedUntil - obj.currentTime
if cachedFor:
self.log("%s: cached (%d seconds)" % (path, cachedFor))
cachedUntil = time.time() + cachedFor
# store in memory
cached = self.cache[key] = (cachedUntil, doc)
# store in cache folder
cacheFile = join(self.tempdir, str(key) + ".cache")
f = open(cacheFile, "wb")
f.write(zlib.compress(pickle.dumps(cached, -1)))
f.close()
auth = api.auth(keyID=CORP_KEYID, vCode=CORP_VCODE)
result2 = auth.account.Characters()
cachedApi = eveapi.EVEAPIConnection(cacheHandler=MyCacheHandler(debug=True))
# Now the best way to iterate over the characters on your account and show
# the isk balance is probably this way:
for character in result2.characters:
if "Flicky G" == character.name:
wallet = auth.corp.AccountBalance(characterID=character.characterID)
for x in wallet.accounts:
print (x)
corp = cachedApi.auth(keyID=1383071, vCode="m0ecx5e1r8RCMsizNKXyB91HQchkHjJmNJlG8or0xy3VvkpiAJj1J7wXb70lUMm0").corporation(98436502)
corpTransactions = corp.WalletTransactions()
for x in corpTransactions.transactions:
print (x)
corpJournal = corp.WalletJournal()
for x in corpJournal.entries:
print (x)
corpAssets = corp.AssetList().assets
for x in corpAssets:
print (x)
firstGo.createCorpAssetsTable(corpAssets)
firstGo.getValueCorpAssets()
#itemID, locationID, typeID, quantity, flag, singleton
for x in corpAssets:
print (firstGo.getItemName(x["typeID"]), firstGo.nowValueJita(x["typeID"]))
####################