diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2022-07-05 16:30:42 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2022-07-05 16:30:42 +0300 |
commit | 87fd2600515dea981bf909c15d43638aac490633 (patch) | |
tree | d88bfcbf28cd5f9dc43622164f5bb453c4fe4a10 /parsers/QMs.py | |
parent | 5d7d2b82b2f47b748a589d946cc52a2e1e8f2893 (diff) | |
download | troggle-87fd2600515dea981bf909c15d43638aac490633.tar.gz troggle-87fd2600515dea981bf909c15d43638aac490633.tar.bz2 troggle-87fd2600515dea981bf909c15d43638aac490633.zip |
import diagnostics
Diffstat (limited to 'parsers/QMs.py')
-rw-r--r-- | parsers/QMs.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/parsers/QMs.py b/parsers/QMs.py index 94088cf..ca6583b 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -55,8 +55,8 @@ def parseCaveQMs(cave,inputFile): message = f' ! - {qmPath} KH is not in the database. Please run cave parser' print(message) DataIssue.objects.create(parser='QMs', message=message) - parse_KH_QMs(kh, inputFile=inputFile) - return + nqms = parse_KH_QMs(kh, inputFile=inputFile) + return nqms #qmPath = settings.EXPOWEB+inputFile qmPath = os.path.join(settings.EXPOWEB, inputFile) @@ -67,6 +67,7 @@ def parseCaveQMs(cave,inputFile): qmReader = csv.reader(qmCSVContents,dialect=dialect) next(qmReader) # Skip header row n = 0 + nqms = 0 for line in qmReader: try: n += 1 @@ -111,7 +112,7 @@ def parseCaveQMs(cave,inputFile): except QM.DoesNotExist: #if there is no pre-existing QM, save the new one newQM.save() - + nqms += 1 except KeyError: #check on this one message = f' ! - {qmPath} KeyError {str(line)} ' print(message) @@ -122,12 +123,14 @@ def parseCaveQMs(cave,inputFile): print(message) DataIssue.objects.create(parser='QMs', message=message) continue + return nqms def parse_KH_QMs(kh, inputFile): """import QMs from the 1623-161 (Kaninchenhohle) html pages, different format """ khQMs=open(os.path.join(settings.EXPOWEB, inputFile),'r') khQMs=khQMs.readlines() + nqms = 0 for line in khQMs: res=re.search(r'name=\"[CB](?P<year>\d*)-(?P<cave>\d*)-(?P<number>\d*).*</a> (?P<grade>[ABDCV])<dd>(?P<description>.*)\[(?P<nearest_station>.*)\]',line) if res: @@ -151,10 +154,16 @@ def parse_KH_QMs(kh, inputFile): } save_carefully(QM,lookupArgs,nonLookupArgs) + nqms += 1 + return nqms + def Load_QMs(): deleteQMs() - parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv") - parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv") - parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm") + n204 = parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv") + n234 = parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv") + n161 = parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm") #parseCaveQMs(cave='balkonhoehle',inputFile=r"1623/264/qm.csv") + print(f" - Imported: {n204} QMs for 204, {n234} QMs for 234, {n161} QMs for 161.") + + print () |