diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-10-23 22:54:46 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-10-23 22:54:46 +0300 |
commit | 33477f2b40a5e88379d2d05cfc5356afdbb06269 (patch) | |
tree | 62d029458a69991bfe4de4a6a27d049696f28b39 /parsers | |
parent | b522899216695187f70f8c35aef6c962124d3308 (diff) | |
download | troggle-33477f2b40a5e88379d2d05cfc5356afdbb06269.tar.gz troggle-33477f2b40a5e88379d2d05cfc5356afdbb06269.tar.bz2 troggle-33477f2b40a5e88379d2d05cfc5356afdbb06269.zip |
refactoring duplicate code
Diffstat (limited to 'parsers')
-rw-r--r-- | parsers/scans.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/parsers/scans.py b/parsers/scans.py index 96c490a..b9bae25 100644 --- a/parsers/scans.py +++ b/parsers/scans.py @@ -13,15 +13,14 @@ contentsjson = "contents.json" git = settings.GIT -# to do: Actually read all the JSON files and set the survex file field appropriately! - def set_walletyear(wallet): _ = wallet.year() # don't need return value. Just calling this saves it as w.walletyear Syntactic. def set_JSONwalletdate(wallet): """At this point in the import process, the survex files have not been imported so - we cannot get dates from them. There are about 40 JSON files (in 2022) which we read here.""" + we cannot get dates from them. There are about 40 JSON files (in 2022) which we read here. + Actually, doing anything that reads the JSON sets .walletdate""" _ = wallet.date() # don't need return value. Sets .walletdate as side effect def set_caves(wallet): @@ -111,11 +110,11 @@ def load_all_scans(): else: print("", flush=True, end="") # Create the wallet object. But we don't have a date for it yet. - wallet = Wallet(fpath=fpath, walletname=walletname) + wallet = Wallet.objects.create(walletname=walletname, fpath=fpath) wallets[walletname] = wallet set_walletyear(wallet) - wallet.save() set_caves(wallet) + wallet.save() singlescan = SingleScan(ffile=fpath, name=p.name, wallet=wallet) singlescan.save() @@ -156,15 +155,13 @@ def load_all_scans(): # The wallets found from JSON should all have dates already wallet, created = Wallet.objects.update_or_create(walletname=walletname, fpath=fpath) wallets[walletname] = wallet - # Now also load the json - set_JSONwalletdate(wallet) set_walletyear(wallet) set_caves(wallet) + wallet.save() if not created: print( f"\n - {walletname} was not created, but was not in directory walk of /surveyscans/. Who created it?" ) - wallet.save() print(f"\n - found another {wjson:,} JSON files, making a total of {len(wallets):,} wallets") # Only the 1999 wallets have filenames which mean that the walletyear will be unset: |