mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Split the config code to a new module resolving #81
This commit is contained in:
parent
966ec64e84
commit
e8fc3eb9ad
12
configloader.py
Normal file
12
configloader.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import json, sys, logging
|
||||||
|
|
||||||
|
try: # load settings
|
||||||
|
with open("settings.json") as sfile:
|
||||||
|
settings = json.load(sfile)
|
||||||
|
if settings["limitrefetch"] < settings["limit"] and settings["limitrefetch"] != -1:
|
||||||
|
settings["limitrefetch"] = settings["limit"]
|
||||||
|
if "user-agent" in settings["header"]:
|
||||||
|
settings["header"]["user-agent"] = settings["header"]["user-agent"].format(version="1.6.0.1") # set the version in the useragent
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.critical("No config file could be found. Please make sure settings.json is in the directory.")
|
||||||
|
sys.exit(1)
|
1
misc.py
1
misc.py
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
import json, logging, sys, re
|
import json, logging, sys, re
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
from configloader import settings
|
||||||
|
|
||||||
# Create a custom logger
|
# Create a custom logger
|
||||||
|
|
||||||
|
|
15
rcgcdw.py
15
rcgcdw.py
|
@ -25,6 +25,7 @@ from bs4 import BeautifulSoup
|
||||||
from collections import defaultdict, Counter
|
from collections import defaultdict, Counter
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
from configloader import settings
|
||||||
|
|
||||||
if __name__ != "__main__": # return if called as a module
|
if __name__ != "__main__": # return if called as a module
|
||||||
logging.critical("The file is being executed as a module. Please execute the script using the console.")
|
logging.critical("The file is being executed as a module. Please execute the script using the console.")
|
||||||
|
@ -32,23 +33,11 @@ if __name__ != "__main__": # return if called as a module
|
||||||
|
|
||||||
TESTING = True if "--test" in sys.argv else False # debug mode, pipeline testing
|
TESTING = True if "--test" in sys.argv else False # debug mode, pipeline testing
|
||||||
|
|
||||||
try: # load settings
|
|
||||||
with open("settings.json") as sfile:
|
|
||||||
settings = json.load(sfile)
|
|
||||||
if settings["limitrefetch"] < settings["limit"] and settings["limitrefetch"] != -1:
|
|
||||||
settings["limitrefetch"] = settings["limit"]
|
|
||||||
if "user-agent" in settings["header"]:
|
|
||||||
settings["header"]["user-agent"] = settings["header"]["user-agent"].format(version="1.6.0.1") # set the version in the useragent
|
|
||||||
except FileNotFoundError:
|
|
||||||
logging.critical("No config file could be found. Please make sure settings.json is in the directory.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
logging.debug("Current settings: {settings}".format(settings=settings))
|
|
||||||
|
|
||||||
# Prepare logging
|
# Prepare logging
|
||||||
|
|
||||||
logging.config.dictConfig(settings["logging"])
|
logging.config.dictConfig(settings["logging"])
|
||||||
logger = logging.getLogger("rcgcdw")
|
logger = logging.getLogger("rcgcdw")
|
||||||
|
logger.debug("Current settings: {settings}".format(settings=settings))
|
||||||
|
|
||||||
# Setup translation
|
# Setup translation
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue