Skip to content

Commit

Permalink
Maddavo plugin improvements:
Browse files Browse the repository at this point in the history
Switched to NOTE for quiescable output,
--opt=skipdl will force a parse,
Added some DEBUG lines
  • Loading branch information
kfsone committed Jan 1, 2015
1 parent 68b6767 commit e7b41c0
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions plugins/maddavo_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def run(self):
self.prevImportDate = prevImportDate

cacheNeedsRebuild = self.getOption("buildcache")
if not self.getOption("skipdl"):
skipDownload = self.getOption("skipdl")
forceParse = self.getOption("force") or skipDownload

if not skipDownload:
if self.getOption("syscsv"):
transfers.download(
tdenv,
Expand All @@ -131,18 +134,18 @@ def run(self):
if lastRunDays < 1.9:
priceFile = "prices-2d.asp"
else:
if not tdenv.quiet:
if lastRunDays < 99:
print(
"NOTE: Last download was ~{:.2f} days "
"ago, downloading full file".format(
lastRunDays
))
else:
print(
"NOTE: Stale/missing local copy, "
"downloading full .prices file."
)
if lastRunDays < 99:
tdenv.NOTE(
"Last download was ~{:.2f} days "
"ago, downloading full file",
lastRunDays
)
else:
tdenv.NOTE(
"Stale/missing local copy, "
"downloading full .prices file."
)

priceFile = "prices.asp"
transfers.download(
tdenv,
Expand All @@ -153,12 +156,13 @@ def run(self):

if tdenv.download:
if cacheNeedsRebuild:
print("NOTE: Did not rebuild cache")
tdenv.NOTE("Did not rebuild cache")
return False

tdenv.ignoreUnknown = True

# Let the system decide if it needs to reload-cache
tdenv.DEBUG0("Checking the cache")
tdb.close()
tdb.reloadCache()
tdb.load(
Expand All @@ -174,6 +178,7 @@ def run(self):
dateRe = ImportPlugin.dateRe
lastStn = None
updatedStations = set()
tdenv.DEBUG0("Reading prices data")
with open("import.prices", "rU", encoding="utf-8") as fh:
# skip the shebang.
firstLine = fh.readline()
Expand Down Expand Up @@ -205,10 +210,10 @@ def run(self):
date
))

if numNewLines == 0 and not tdenv.quiet:
print("No new price entries found.")
if numNewLines == 0:
tdenv.NOTE("No new price entries found.")

if numNewLines > 0 or self.getOption("force"):
if numNewLines > 0 or forceParse:
if tdenv.detail:
print(
"Date of last import : {}\n"
Expand All @@ -228,11 +233,11 @@ def run(self):
if not tdenv.quiet and numStationsUpdated:
if len(updatedStations) > 12 and tdenv.detail < 2:
updatedStations = list(updatedStations)[:10] + ["..."]
print("{} {} updated:\n{}".format(
tdenv.NOTE("{} {} updated:\n{}",
numStationsUpdated,
"stations" if numStationsUpdated > 1 else "station",
', '.join(updatedStations)
))
)

cache.importDataFromFile(
tdb,
Expand Down

0 comments on commit e7b41c0

Please sign in to comment.