simple app
This commit is contained in:
commit
cf677c0787
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
poetry.lock
|
||||||
|
local
|
||||||
|
local/**
|
||||||
|
temp
|
||||||
|
temp/**
|
||||||
|
.idea
|
||||||
|
.idea/**
|
16
pyproject.toml
Normal file
16
pyproject.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "rss-feedler"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = ["bvn13 <from.github@bvn13.me>"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.12"
|
||||||
|
requests = "^2.32.3"
|
||||||
|
urllib3 = "^2.2.3"
|
||||||
|
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
47
src/app.py
Normal file
47
src/app.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
|
||||||
|
import requests.exceptions
|
||||||
|
from requests import Session
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
from urllib3.util import Retry
|
||||||
|
from src.logger import logger as l
|
||||||
|
|
||||||
|
|
||||||
|
logger = l.getChild(__name__)
|
||||||
|
logger.info("Starting")
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(__name__)
|
||||||
|
parser.add_argument('-s', '--settings', required=True, help='Settings JSON')
|
||||||
|
parser.add_argument('-d', '--directory', required=True, help='Directory to store XMLs')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
logger.info("Loading settings from settings JSON")
|
||||||
|
settings = []
|
||||||
|
with open(args.settings) as json_file:
|
||||||
|
settings = json.load(json_file)
|
||||||
|
|
||||||
|
assert type(settings) == list
|
||||||
|
|
||||||
|
for sets in settings:
|
||||||
|
logger.info(f"Working set: {sets}")
|
||||||
|
assert type(sets) == dict
|
||||||
|
assert 'src' in sets
|
||||||
|
assert 'rss' in sets
|
||||||
|
s = Session()
|
||||||
|
retries = Retry(
|
||||||
|
total=3,
|
||||||
|
backoff_factor=0.1,
|
||||||
|
status_forcelist=[502, 503, 504],
|
||||||
|
allowed_methods={'GET'},
|
||||||
|
)
|
||||||
|
s.mount(sets['src'], HTTPAdapter(max_retries=retries))
|
||||||
|
try:
|
||||||
|
r = s.get(sets['src'], timeout=3, stream=True)
|
||||||
|
if r.status_code == 200:
|
||||||
|
logger.info(f"Saving to file: {sets['rss']}")
|
||||||
|
with open("{0}/{1}".format(args.directory, sets['rss']), 'wb') as rss:
|
||||||
|
for chunk in r:
|
||||||
|
rss.write(chunk)
|
||||||
|
except requests.exceptions.ConnectionError as e:
|
||||||
|
logger.warning(f"Unable to fetch {sets['src']}", e)
|
5
src/logger.py
Normal file
5
src/logger.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(format="%(asctime)s | %(name)s | %(levelname)s | %(message)s")
|
||||||
|
logger = logging.getLogger(__package__)
|
||||||
|
logger.setLevel(logging.INFO)
|
Loading…
Reference in New Issue
Block a user