-
Notifications
You must be signed in to change notification settings - Fork 17
/
getgroups-esi.py
157 lines (109 loc) · 4.3 KB
/
getgroups-esi.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
import requests
from sqlalchemy import create_engine,MetaData,Table,Column,INTEGER,FLOAT,VARCHAR,UnicodeText,DECIMAL,Boolean,select,literal_column
import requests_cache
from requests_futures.sessions import FuturesSession
import requests_futures
from concurrent.futures import as_completed
from tqdm import tqdm
import sys
def getgroups(grouplist):
groupfuture=[]
print "getgroups"
for groupid in grouplist:
if isinstance(groupid,basestring) and groupid.startswith("https"):
groupfuture.append(session.get(str(groupid)))
else:
groupfuture.append(session.get(grouplookupurl.format(groupid)))
badlist=[]
pbar = tqdm(total=len(grouplist))
for groupdata in as_completed(groupfuture):
if groupdata.result().status_code==200:
itemjson=groupdata.result().json()
item=itemjson.get('group_id')
if int(item) in sdegrouplist:
try:
connection.execute(invGroups.update().where(invGroups.c.groupID == literal_column(str(item))),
groupID=item,
groupName=itemjson['name'],
categoryID=itemjson.get('category_id',None),
published=itemjson.get('published',False),
)
except:
pass
else:
connection.execute(invGroups.insert(),
groupID=item,
groupName=itemjson['name'],
categoryID=itemjson.get('category_id',None),
published=itemjson.get('published',False),
)
else:
badlist.append(groupdata.result().url)
print groupdata.result().url
pbar.update(1)
return badlist
if len(sys.argv)<2:
print "Load.py destination"
exit()
database=sys.argv[1]
if len(sys.argv)==3:
language=sys.argv[2]
else:
language='en'
import ConfigParser, os
fileLocation = os.path.dirname(os.path.realpath(__file__))
inifile=fileLocation+'/sdeloader.cfg'
config = ConfigParser.ConfigParser()
config.read(inifile)
destination=config.get('Database',database)
sourcePath=config.get('Files','sourcePath')
schema=None
if database=="postgresschema":
schema="evesde"
engine = create_engine(destination, echo=False)
metadata = MetaData(schema=schema)
connection = engine.connect()
trans = connection.begin()
invGroups = Table('invGroups', metadata,
Column('groupID', INTEGER(), primary_key=True, autoincrement=False, nullable=False),
Column('categoryID', INTEGER(),index=True),
Column('groupName', VARCHAR(length=100)),
Column('iconID', INTEGER()),
Column('useBasePrice', Boolean(name='invgroup_usebaseprice')),
Column('anchored', Boolean(name='invgroup_anchored')),
Column('anchorable', Boolean(name='invgroup_anchorable')),
Column('fittableNonSingleton', Boolean(name='invgroup_fitnonsingle')),
Column('published', Boolean(name='invgroup_published')),
schema=schema
)
maingrouplist=[]
groupurl="https://esi.evetech.net/latest/universe/groups/?datasource=tranquility&page={}"
grouplookupurl='https://esi.evetech.net/latest/universe/groups/{}/'
errorcount=0
requests_cache.install_cache("group_cache",backend='redis',expire_after=35000)
base_session=requests_cache.core.CachedSession(cache_name="item_cache",backend='redis',expire_after=35000)
lookup=select([invGroups])
result=connection.execute(lookup).fetchall()
sdegrouplist=[]
for groupdata in result:
sdegrouplist.append(groupdata.groupID)
reqs_num_workers=50
session = FuturesSession(max_workers=reqs_num_workers,session=base_session)
page=1
groups=requests.get(groupurl.format(page))
page+=1
groupjson=groups.json()
maingrouplist=maingrouplist+groupjson
maxpage=int(groups.headers['x-pages'])
pbar = tqdm(total=maxpage)
while page<=maxpage:
groups=requests.get(groupurl.format(page))
page+=1
pbar.update(1)
groupjson=groups.json()
maingrouplist=maingrouplist+groupjson
print "Page variable is {}".format(page)
firstbadlist=getgroups(maingrouplist)
print "Getting badlist"
secondbadlist=getgroups(firstbadlist)
trans.commit()