Bump to version 1.0.0 - Probably should have been new branch!!!!
This commit is contained in:
parent
f3b7ffb3a1
commit
9db0aab561
@ -4,6 +4,7 @@ import requests
|
||||
import logger as log
|
||||
import zlib
|
||||
import json
|
||||
import mongo
|
||||
|
||||
CORPUS_URL = "https://publicdatafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS"
|
||||
|
||||
@ -15,6 +16,7 @@ CORPUS_PASS = os.getenv('OWL_LDB_CORPUSPASS')
|
||||
def fetch():
|
||||
log.out("corpus.fetch: Fetching CORPUS Data from Network Rail", "INFO")
|
||||
response = requests.get(CORPUS_URL, auth=(CORPUS_USER, CORPUS_PASS))
|
||||
incrementCounter("corpus_api")
|
||||
log.out("corpus.fetch: Decompressing & parsing CORPUS data", "INFO")
|
||||
parsed = json.loads(zlib.decompress(response.content, 16+zlib.MAX_WBITS).decode())
|
||||
return parsed['TIPLOCDATA']
|
||||
|
@ -14,7 +14,7 @@
|
||||
# program. If not, see
|
||||
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
|
||||
|
||||
version = "0.1.7"
|
||||
version = "1.0.0"
|
||||
print(f"main.py: Initialising db-manager v{version}")
|
||||
|
||||
#Third Party Imports
|
||||
|
14
src/mongo.py
14
src/mongo.py
@ -18,6 +18,7 @@ db = client[db_name]
|
||||
def metaCheckTime(target):
|
||||
col = db["meta"]
|
||||
res = col.find_one({"target": target, "type": "collection"})
|
||||
incrementCounter("meta")
|
||||
if type(res) is dict:
|
||||
if 'updated' in res:
|
||||
log.out(f'mongo.metaUpdateTime: {target} last updated at {res["updated"]}', "INFO")
|
||||
@ -29,22 +30,25 @@ def metaUpdateTime(target):
|
||||
col = db["meta"]
|
||||
log.out(f'mongo.metaUpdateTime: Updating updated time for {target}', "INFO")
|
||||
res = col.update_one({"target": target, "type":"collection"}, {"$set":{"updated": int(time.time()),"target":target, "type":"collection"}}, upsert=True)
|
||||
incrementCounter("meta")
|
||||
|
||||
def getLength(collection):
|
||||
col = db[collection]
|
||||
incrementCounter(collection)
|
||||
return col.count_documents({})
|
||||
|
||||
def createSingleIndex(collection, field):
|
||||
col = db[collection]
|
||||
col.create_index(field)
|
||||
incrementCounter(collection)
|
||||
log.out(f'mongo.createSingleIndex: Created index of {field} in {collection}', "INFO")
|
||||
return
|
||||
|
||||
|
||||
def putBulkCorpus(data):
|
||||
collection = "corpus"
|
||||
startCount = getLength(collection)
|
||||
col = db[collection]
|
||||
incrementCounter(collection)
|
||||
if startCount > 0:
|
||||
log.out(f'mongo.putBulkCorpus: Dropping {startCount} CORPUS documents', "INFO")
|
||||
col.drop()
|
||||
@ -63,6 +67,7 @@ def putBulkStations(data):
|
||||
collection = "stations"
|
||||
startCount = getLength(collection)
|
||||
col = db[collection]
|
||||
incrementCounter("stations")
|
||||
if startCount > 0:
|
||||
log.out(f'mongo.putBulkStations: Dropping {startCount} station documents', "INFO")
|
||||
col.drop()
|
||||
@ -78,9 +83,16 @@ def putBulkStations(data):
|
||||
metaUpdateTime(collection)
|
||||
return
|
||||
|
||||
def incrementCounter(target):
|
||||
collection = "meta"
|
||||
col = db[collection]
|
||||
col.update_one({"target": "counters"}, {"$inc":target})
|
||||
return
|
||||
|
||||
def metaCounters():
|
||||
collection = "meta"
|
||||
col = db[collection]
|
||||
incrementCounter(collection)
|
||||
res = col.find_one({"target": "counters","type": "count"})
|
||||
log.out(f'mongo.metaCounters: Query returned `{res}`', "DEBG")
|
||||
if type(res) is dict:
|
||||
|
Reference in New Issue
Block a user