Compare commits

...

6 Commits

Author SHA1 Message Date
jeancf
373aa5ebc8 Changed WARN in WARNING 2022-12-04 12:52:54 +01:00
jeancf
b76d1b5812 Try disable all logging 2022-12-04 12:49:41 +01:00
jeancf
33b103a520 Corrected setLevel() 2022-12-04 12:43:11 +01:00
jeancf
b142664ef7 Added log verbosity to config file 2022-12-04 11:45:53 +01:00
jeancf
c9d4775085 Merge branch 'susbt' of https://gitlab.com/jeancf/twoot into susbt 2022-12-04 11:25:14 +01:00
jeancf
c07a3b17c1 Refined substitute_source() 2022-12-04 11:25:02 +01:00
2 changed files with 33 additions and 8 deletions

View File

@ -67,3 +67,8 @@ subst_youtube = []
# e.g. subst_reddit = ["teddit.net", ]
# Default is []
subst_reddit = []
# Verbosity of log messages
# One of DEBUG, INFO, WARNING, ERROR, CRITICAL
# Default is "WARNING"
log_level = "WARNING"

View File

@ -38,10 +38,6 @@ from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalA
# Number of records to keep in db table for each twitter account
MAX_REC_COUNT = 50
# Set the desired verbosity of logging
# One of logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL
LOGGING_LEVEL = logging.INFO
# How many seconds to wait before giving up on a download (except video download)
HTTPS_REQ_TIMEOUT = 10
@ -94,6 +90,7 @@ def build_config(args):
'subst_twitter': [],
'subst_youtube': [],
'subst_reddit': [],
'log_level': "WARNING"
}
# Create default config object
@ -259,19 +256,22 @@ def substitute_source(orig_url):
# Handle twitter
twitter_subst = TOML["options"]["subst_twitter"]
if domain.find('twitter.com') >=0 and twitter_subst != []:
# Do not substitiute if subdomain is present (e.g. i.twitter.com)
if (domain == 'twitter.com' or domain == 'www.twitter.com') and twitter_subst != []:
domain = twitter_subst[random.randint(0, len(twitter_subst) - 1)]
logging.debug("Replaced twitter.com by " + domain)
# Handle youtube
youtube_subst = TOML["options"]["subst_youtube"]
if domain.find('youtube.com') >=0 and youtube_subst != []:
# Do not substitiute if subdomain is present (e.g. i.youtube.com)
if (domain == 'youtube.com' or domain == 'wwww.youtube.com') and youtube_subst != []:
domain = youtube_subst[random.randint(0, len(youtube_subst) - 1)]
logging.debug("Replaced youtube.com by " + domain)
# Handle reddit
reddit_subst = TOML["options"]["subst_reddit"]
if domain.find('reddit.com') >=0 and reddit_subst != []:
# Do not substitiute if subdomain is present (e.g. i.reddit.com)
if (domain == 'reddit.com' or domain == 'www.reddit.com') and reddit_subst != []:
domain = reddit_subst[random.randint(0, len(reddit_subst) - 1)]
logging.debug("Replaced reddit.com by " + domain)
@ -582,11 +582,31 @@ def main(argv):
# Setup logging to file
logging.basicConfig(
filename=TOML['config']['twitter_account'] + '.log',
level=LOGGING_LEVEL,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
# Set level of logging
log_level = logging.WARNING
match TOML['options']['log_level'].upper():
case 'DEBUG':
log_level = logging.DEBUG
case 'INFO':
log_level = logging.INFO
case 'WARNING':
log_level = logging.WARNING
case 'ERROR':
log_level = logging.ERROR
case 'CRITICAL':
log_level = logging.CRITICAL
case 'OFF':
# Disable all logging
logging.disable(logging.CRITICAL)
case _:
logging.error('Invalid log_level %s in config file. Using WARNING.', str(TOML['options']['log_level']))
logger = logging.getLogger()
logger.setLevel(log_level)
logging.info('Running with the following configuration:')
logging.info(' Config File : ' + str(args['f']))
logging.info(' twitter_account : ' + TOML['config']['twitter_account'])