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