From e7b41c09aa9a2a0ddea3ea5d8169dacd2f71cbbd Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 1 Jan 2015 12:47:23 -0800 Subject: [PATCH] Maddavo plugin improvements: Switched to NOTE for quiescable output, --opt=skipdl will force a parse, Added some DEBUG lines --- plugins/maddavo_plug.py | 43 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/plugins/maddavo_plug.py b/plugins/maddavo_plug.py index aee9210f..6030882c 100644 --- a/plugins/maddavo_plug.py +++ b/plugins/maddavo_plug.py @@ -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, @@ -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, @@ -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( @@ -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() @@ -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" @@ -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,