Compare commits
No commits in common. "main" and "feature/rss-image-thumbnails" have entirely different histories.
main
...
feature/rs
1 changed files with 42 additions and 45 deletions
87
discorss.py
87
discorss.py
|
|
@ -60,47 +60,6 @@ class Discorss:
|
||||||
self.app_config = {}
|
self.app_config = {}
|
||||||
print(f"Logging to {self.log_file_path}")
|
print(f"Logging to {self.log_file_path}")
|
||||||
|
|
||||||
self.now = time.mktime(time.localtime())
|
|
||||||
# Set up logging
|
|
||||||
self.logger = logging.getLogger(__name__)
|
|
||||||
logging.basicConfig(
|
|
||||||
filename=self.log_file_path,
|
|
||||||
encoding="utf-8",
|
|
||||||
level=logging.DEBUG,
|
|
||||||
datefmt="%m/%d/%Y %H:%M:%S",
|
|
||||||
format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s",
|
|
||||||
)
|
|
||||||
# Check for log and config files/paths, create empty directories if needed
|
|
||||||
# TODO: change output to log file, as warning/error
|
|
||||||
if not Path(self.log_dir).exists():
|
|
||||||
self.logger.warning(
|
|
||||||
"No log file path exists. Yark! We'll try and make %s...", self.log_dir
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
Path(self.log_dir).mkdir(parents=True, exist_ok=True)
|
|
||||||
except FileExistsError:
|
|
||||||
self.logger.critical(
|
|
||||||
"The path {} already exists and is not a directory!".format(
|
|
||||||
self.log_dir
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if not Path(self.config_file_path).exists():
|
|
||||||
self.logger.warning(
|
|
||||||
"No config file at {}! Snarf. We'll try and make {}...".format(
|
|
||||||
self.config_file_path, self.config_dir
|
|
||||||
)
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
Path(self.config_dir).mkdir(parents=True, exist_ok=True)
|
|
||||||
except FileExistsError:
|
|
||||||
self.warning.critical(
|
|
||||||
"The config dir {} already exists and is not a directory! Please fix manually. Quitting!".format(
|
|
||||||
self.config_dir
|
|
||||||
)
|
|
||||||
)
|
|
||||||
sys.exit(255)
|
|
||||||
return
|
|
||||||
|
|
||||||
async def _fetch_feed(self, hook):
|
async def _fetch_feed(self, hook):
|
||||||
response = await asyncio.to_thread(
|
response = await asyncio.to_thread(
|
||||||
requests.get,
|
requests.get,
|
||||||
|
|
@ -366,14 +325,52 @@ class Discorss:
|
||||||
return False
|
return False
|
||||||
if mime_type and str(mime_type).lower().startswith("image/"):
|
if mime_type and str(mime_type).lower().startswith("image/"):
|
||||||
return True
|
return True
|
||||||
# this will fix urls with ? in them for parameters. this should work
|
|
||||||
# unless the server depends on the parameter to creat the image, but
|
|
||||||
# in that case we'll just hope it has a mime_type instead
|
|
||||||
return str(url).lower().split("?", 1)[0].endswith(self.IMAGE_EXTENSIONS)
|
return str(url).lower().split("?", 1)[0].endswith(self.IMAGE_EXTENSIONS)
|
||||||
|
|
||||||
|
# Some of this could go in __init__
|
||||||
def setup(self):
|
def setup(self):
|
||||||
os.environ["TZ"] = "America/Toronto"
|
os.environ["TZ"] = "America/Toronto"
|
||||||
time.tzset()
|
time.tzset()
|
||||||
|
self.now = time.mktime(time.localtime())
|
||||||
|
# Set up logging
|
||||||
|
self.logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(
|
||||||
|
filename=self.log_file_path,
|
||||||
|
encoding="utf-8",
|
||||||
|
level=logging.DEBUG,
|
||||||
|
datefmt="%m/%d/%Y %H:%M:%S",
|
||||||
|
format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s",
|
||||||
|
)
|
||||||
|
# Check for log and config files/paths, create empty directories if needed
|
||||||
|
# TODO: change output to log file, as warning/error
|
||||||
|
if not Path(self.log_dir).exists():
|
||||||
|
self.logger.warning(
|
||||||
|
"No log file path exists. Yark! We'll try and make %s...", self.log_dir
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
Path(self.log_dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
except FileExistsError:
|
||||||
|
self.logger.critical(
|
||||||
|
"The path {} already exists and is not a directory!".format(
|
||||||
|
self.log_dir
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not Path(self.config_file_path).exists():
|
||||||
|
self.logger.warning(
|
||||||
|
"No config file at {}! Snarf. We'll try and make {}...".format(
|
||||||
|
self.config_file_path, self.config_dir
|
||||||
|
)
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
Path(self.config_dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
except FileExistsError:
|
||||||
|
self.warning.critical(
|
||||||
|
"The config dir {} already exists and is not a directory! Please fix manually. Quitting!".format(
|
||||||
|
self.config_dir
|
||||||
|
)
|
||||||
|
)
|
||||||
|
sys.exit(255)
|
||||||
|
return
|
||||||
# Loading the config file
|
# Loading the config file
|
||||||
with open(self.config_file_path, "r") as config_file:
|
with open(self.config_file_path, "r") as config_file:
|
||||||
self.app_config = json.load(config_file)
|
self.app_config = json.load(config_file)
|
||||||
|
|
@ -405,7 +402,7 @@ class Discorss:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="\x1b[1;34mDisco\x1b[33mRSS\x1b[0m: publish feed updates to Discord webhooks."
|
description="DiscoRSS: publish feed updates to Discord webhooks."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue