Skip to content

Commit

Permalink
Call new EDCD plugin for option 'edcd'
Browse files Browse the repository at this point in the history
  • Loading branch information
bgol committed Jul 6, 2016
1 parent 749f47b commit 1a53ea6
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions plugins/edapi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import mapping
import transfers

__version_info__ = ('3', '7', '1')
__version_info__ = ('3', '7', '2')
__version__ = '.'.join(__version_info__)

# ----------------------------------------------------------------
Expand Down Expand Up @@ -378,7 +378,7 @@ class ImportPlugin(plugins.ImportPluginBase):
'csvs': 'Merge shipyards into ShipVendor.csv.',
'name': 'Do not obfuscate commander name for EDDN submit.',
'save': 'Save the API response (tmp/profile.YYYYMMDD_HHMMSS.json).',
'edcd': 'Download current FDevIDs from EDCD',
'edcd': 'Call the EDCD plugin first',
'eddn': 'Post market, shipyard and outfitting to EDDN.',
}

Expand All @@ -391,49 +391,23 @@ def __init__(self, tdb, tdenv):
cookieFilePath = pathlib.Path(ImportPlugin.cookieFile)
self.cookiePath = tdb.dataPath / cookieFilePath

def download_fdevids(self):
"""
Download the current Shipyard and Outfitting data
from EDCD, see https://github.com/EDCD/FDevIDs
"""
tdb, tdenv = self.tdb, self.tdenv

baseUrl = "https://raw.githubusercontent.com/EDCD/FDevIDs/master/"
downloadList = [
('FDevShipyard', 'FDevShipyard.csv', 'shipyard.csv'),
('FDevOutfitting', 'FDevOutfitting.csv', 'outfitting.csv'),
]

db = tdb.getDB()
for tableName, fileTD, fileEDCD in downloadList:
localPath = tdb.dataPath / pathlib.Path(fileTD)
transfers.download(
tdenv,
baseUrl + fileEDCD,
str(localPath),
)
db.execute("DELETE FROM {}".format(tableName))
cache.processImportFile(
tdenv,
db,
localPath,
tableName
)
lines, csvPath = csvexport.exportTableToFile(
tdb,
tdenv,
tableName,
)
tdenv.NOTE("{} updated.", csvPath)
db.commit()

def run(self):
tdb, tdenv = self.tdb, self.tdenv

# first check for EDCD
if self.getOption("edcd"):
# download the current FDevIDs from EDCD
self.download_fdevids()
# Call the EDCD plugin
try:
import plugins.edcd_plug as EDCD
except:
raise plugins.PluginException(
"EDCE plugin not found.".format(str(localPath))
)
tdenv.NOTE("Calling the EDCD plugin.")
edcdPlugin = EDCD.ImportPlugin(tdb, tdenv)
edcdPlugin.options["csvs"] = True
edcdPlugin.run()
tdenv.NOTE("Going back to EDAPI.\n")

# now load the mapping tables
itemMap = mapping.FDEVMappingItems(tdb, tdenv)
Expand Down

0 comments on commit 1a53ea6

Please sign in to comment.