mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-22 08:12:15 +00:00
Compare commits
6 Commits
64c4279d6e
...
373aa5ebc8
Author | SHA1 | Date | |
---|---|---|---|
|
373aa5ebc8 | ||
|
b76d1b5812 | ||
|
33b103a520 | ||
|
b142664ef7 | ||
|
c9d4775085 | ||
|
c07a3b17c1 |
|
@ -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"
|
||||
|
|
36
twoot.py
36
twoot.py
|
@ -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'])
|
||||
|
|
Loading…
Reference in New Issue
Block a user