This repository has been archived on 2024-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
db-manager/src/main.py

56 lines
2.2 KiB
Python
Raw Normal View History

2023-02-11 12:03:39 +00:00
# db-manager - Builds and manages an OwlBoard database instance - To be run on a
# cron schedule
2023-02-09 20:58:48 +00:00
# Copyright (C) 2023 Frederick Boniface
2023-02-11 12:03:39 +00:00
# This program is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
2023-02-09 20:58:48 +00:00
2023-02-11 12:03:39 +00:00
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
2023-02-09 20:58:48 +00:00
2023-02-11 12:03:39 +00:00
# You should have received a copy of the GNU General Public License along with this
# program. If not, see
2023-02-09 21:47:59 +00:00
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
2023-02-11 22:05:30 +00:00
version = "0.1.0"
print(f"main.py: Initialising db-manager v{version}")
2023-02-11 12:03:39 +00:00
2023-02-11 15:16:25 +00:00
#Third Party Imports
2023-02-09 21:47:59 +00:00
import os
import time
2023-02-11 15:16:25 +00:00
#Local Imports
2023-02-11 22:05:30 +00:00
import corpus, mongo
2023-02-11 15:16:25 +00:00
import logger as log
2023-02-09 21:47:59 +00:00
2023-02-11 22:05:30 +00:00
log.out("main.py: db-manager Initialised", "INFO")
#Check & Update corpus/stations:
# If older than 12 days then update
corpusAge = int(time.time()) - mongo.metaCheckTime("corpus")
log.out(f'main.py: Corpus is {corpusAge}s old', "INFO")
if corpusAge > 1036800:
log.out('main.py: Updating CORPUS data', "INFO")
corpusData = corpus.removeEmpty(corpus.fetch())
mongo.putBulkCorpus(corpusData)
else:
log.out('main.py: Not updating CORPUS data', "INFO")
stationsAge = int(time.time()) - mongo.metaCheckTime("stations")
log.out(f'main.py: Stations is {stationsAge}s old', "INFO")
# While the source of stations data is CORPUS, this statement is based on corpusAge, when/if changing the source, it should be changed to use stationsAge
# if stationsAge is used now, there could be a situation where stationsAge tries to update but fails as corpusData doesn't exist.
if corpusAge > 1036800:
log.out('main.py: Updating stations data', "INFO")
stationData = corpus.onlyStations(corpusData)
mongo.putBulkStations(stationData)
else:
log.out('main.py: Not updating stations data', "INFO")
2023-02-12 20:56:46 +00:00
#Ensure count document exists in meta:
2023-02-12 21:36:41 +00:00
mongo.metaCounters()
2023-02-11 22:05:30 +00:00
# END
log.out(f"main.py: db-manager v{version} Complete", "INFO")