mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 07:47:14 +03:00
Add support for saving in CSV format.
This commit is contained in:
parent
0a925478b3
commit
29d362a890
@ -147,11 +147,14 @@ class AppWindow:
|
||||
elif not data.get('lastStarport') or not data['lastStarport'].get('commodities'):
|
||||
raise Exception("Station doesn't have a market!")
|
||||
|
||||
if config.read('output') & config.OUT_CSV:
|
||||
bpc.export(data, True)
|
||||
|
||||
if config.read('output') & config.OUT_TD:
|
||||
td.export(data)
|
||||
|
||||
if config.read('output') & config.OUT_BPC:
|
||||
bpc.export(data)
|
||||
bpc.export(data, False)
|
||||
|
||||
if config.read('output') & config.OUT_EDDN:
|
||||
eddn.export(data, self.setstatus)
|
||||
|
@ -4,7 +4,7 @@ Elite: Dangerous Market Connector
|
||||
This app downloads commodity market data from the game [Elite: Dangerous](https://www.elitedangerous.com/) and, at your choice, either:
|
||||
|
||||
* transmits the data to the Elite Dangerous Data Network ("EDDN") from where you and others can use it via online trading tools such as [eddb](http://eddb.io/).
|
||||
* saves the data to files on your disk which you can load into trading tools such as [Slopey's BPC Market Tool](https://forums.frontier.co.uk/showthread.php?t=76081) and [Trade Dangerous](https://bitbucket.org/kfsone/tradedangerous/wiki/Home).
|
||||
* saves the data to files on your disk which you can load into trading tools such as [Slopey's BPC Market Tool](https://forums.frontier.co.uk/showthread.php?t=76081), [Trade Dangerous](https://bitbucket.org/kfsone/tradedangerous/wiki/Home) and [Thrudd's Trading Tools](http://www.elitetradingtool.co.uk/).
|
||||
|
||||
The user-interface is deliberately minimal - just press the "Update" button when you land at a station to automatically download and transmit or save the station's commodity market data:
|
||||
|
||||
|
17
bpc.py
17
bpc.py
@ -8,21 +8,26 @@ import time
|
||||
from config import config
|
||||
from companion import commoditymap, bracketmap
|
||||
|
||||
def export(data):
|
||||
def export(data, csv=False):
|
||||
|
||||
querytime = config.read('querytime') or int(time.time())
|
||||
|
||||
filename = join(config.read('outdir'), '%s.%s.%s.bpc' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime))))
|
||||
filename = join(config.read('outdir'), '%s.%s.%s.%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), csv and 'csv' or 'bpc'))
|
||||
|
||||
timestamp = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(querytime))
|
||||
rowheader = '%s;%s;%s' % (data['commander']['name'].replace(';',':').strip(), data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
||||
if csv:
|
||||
header = 'System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
|
||||
rowheader = '%s;%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
||||
else: # bpc
|
||||
header = 'userID;System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
|
||||
rowheader = '%s;%s;%s' % (data['commander']['name'].replace(';',':').strip(), data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
||||
|
||||
h = codecs.open(filename, 'w', 'utf-8')
|
||||
h.write('userID;System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\r\n')
|
||||
h = open(filename, 'wt') # codecs can't automatically handle line endings, so encode manually where required
|
||||
h.write(header.encode('utf-8'))
|
||||
|
||||
for commodity in data['lastStarport']['commodities']:
|
||||
if commodity.get('categoryname') and commodity['categoryname'] != 'NonMarketable':
|
||||
h.write('%s;%s;%s;%s;%s;%s;%s;%s;%s;\r\n' % (
|
||||
h.write('%s;%s;%s;%s;%s;%s;%s;%s;%s;\n' % (
|
||||
rowheader,
|
||||
commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
|
||||
commodity.get('sellPrice') and int(commodity['sellPrice']) or '',
|
||||
|
@ -18,6 +18,7 @@ class Config:
|
||||
OUT_EDDN = 1
|
||||
OUT_BPC = 2
|
||||
OUT_TD = 4
|
||||
OUT_CSV = 8
|
||||
|
||||
if platform=='darwin':
|
||||
|
||||
|
7
prefs.py
7
prefs.py
@ -66,12 +66,13 @@ class PreferencesDialog(tk.Toplevel):
|
||||
ttk.Radiobutton(outframe, text="Online to the Elite Dangerous Data Network (EDDN)", variable=self.outvar, value=config.OUT_EDDN, command=self.outvarchanged).grid(row=1, columnspan=2, padx=5, sticky=tk.W)
|
||||
ttk.Radiobutton(outframe, text="Offline in Slopey's BPC format", variable=self.outvar, value=config.OUT_BPC, command=self.outvarchanged).grid(row=2, columnspan=2, padx=5, sticky=tk.W)
|
||||
ttk.Radiobutton(outframe, text="Offline in Trade Dangerous format", variable=self.outvar, value=config.OUT_TD, command=self.outvarchanged).grid(row=3, columnspan=2, padx=5, sticky=tk.W)
|
||||
ttk.Label(outframe, text=(platform=='darwin' and 'Where:' or 'File location:')).grid(row=4, padx=5, pady=(5,0), sticky=tk.NSEW)
|
||||
ttk.Radiobutton(outframe, text="Offline in CSV format", variable=self.outvar, value=config.OUT_CSV, command=self.outvarchanged).grid(row=4, columnspan=2, padx=5, sticky=tk.W)
|
||||
ttk.Label(outframe, text=(platform=='darwin' and 'Where:' or 'File location:')).grid(row=5, padx=5, pady=(5,0), sticky=tk.NSEW)
|
||||
self.outbutton = ttk.Button(outframe, text=(platform=='darwin' and 'Browse...' or 'Choose...'), command=self.outbrowse)
|
||||
self.outbutton.grid(row=4, column=1, padx=5, pady=(5,0), sticky=tk.NSEW)
|
||||
self.outbutton.grid(row=5, column=1, padx=5, pady=(5,0), sticky=tk.NSEW)
|
||||
self.outdir = ttk.Entry(outframe)
|
||||
self.outdir.insert(0, config.read('outdir'))
|
||||
self.outdir.grid(row=5, columnspan=2, padx=5, pady=5, sticky=tk.EW)
|
||||
self.outdir.grid(row=6, columnspan=2, padx=5, pady=5, sticky=tk.EW)
|
||||
self.outvarchanged()
|
||||
|
||||
if platform=='darwin':
|
||||
|
Loading…
x
Reference in New Issue
Block a user