· 6 years ago · Apr 27, 2019, 12:08 AM
1from esipy import App
2from esipy import EsiClient
3from esipy import EsiSecurity
4import json
5import datetime
6import csv
7import time
8
9def myconverter(o):
10 if isinstance(o, datetime.datetime):
11 return o.__str__()
12
13#This is a file to read a characters orders and dump it to a csv file or json file
14# depending on what the data winds up looking like.
15
16app = App.create(url="https://esi.evetech.net/latest/swagger.json?datasource=tranquility")
17
18security = EsiSecurity(
19 redirect_uri='https://localhost/callback/',
20 client_id='',
21 secret_key='',
22 headers={'User-Agent': ''},
23)
24imported_refresh_token=open("Large_Access_Token.txt","r")
25old_refresh_token = imported_refresh_token.read();
26
27security.update_token({
28 'access_token': '', # leave this empty
29 'expires_in': -1, # seconds until expiry, so we force refresh anyway
30 'refresh_token': old_refresh_token,
31})
32
33# and the client object, replace the header user agent value with something reliable !
34client = EsiClient(
35 retry_requests=True,
36 headers={'User-Agent': 'keith.taylor@brooksny.net'},
37 security=security
38)
39tokens = security.refresh();
40refresh_token_save = tokens['refresh_token'];
41with open("Large_Access_Token.txt.txt","w") as text_file:
42 print(refresh_token_save,file = text_file)
43api_info = security.verify();
44
45op = app.op['get_characters_character_id_search'](
46 categories = 'structure',
47 character_id=api_info['CharacterID'],
48 search = 'D-Pyongyang')
49station_id_output = client.request(op)
50station_dump = json.dumps(station_id_output.data,default = myconverter)
51alt_station_dump = json.loads(station_dump)
52output_string = 'station_id_output.txt';
53
54true_station_id = (alt_station_dump['structure']);
55true_station_id = true_station_id[0];
56open(output_string,'w').write(str(true_station_id))
57
58market_data_end = 0;
59page_pull = 1;
60while market_data_end == 0:
61 imported_refresh_token=open("Large_Access_Token.txt","r")
62 old_refresh_token = imported_refresh_token.read();
63 tokens = security.refresh();
64 refresh_token_save = tokens['refresh_token'];
65 with open("Large_Access_Token.txt","w") as text_file:
66 print(refresh_token_save,file = text_file)
67 api_info = security.verify()
68 op = app.op['get_markets_structures_structure_id'](
69 structure_id = true_station_id,
70 page = page_pull,
71 )
72 orders_output = client.request(op)
73 if not orders_output.data:
74 market_data_end = 1;
75 else:
76 orders_dump = json.dumps(orders_output.data,default = myconverter)
77 output_string = 'EsoMarketDump/Market_dump_' + str(page_pull) + '.txt';
78 open(output_string,'w').write(orders_dump)
79 page_pull += 1
80 time.sleep(5)