Commit bc3e0aff authored by Fjen Undso's avatar Fjen Undso
Browse files

Merge branch 'feedgen' into 'master'

replace deprecated werkzeug AtomFeed with feedgen

See merge request !1
parents a4a607cd 4f2a27a9
......@@ -11,10 +11,10 @@ feedparser = "*"
requests = "*"
ipython = "*"
flask = "*"
werkzeug = "<=1"
requests-html = "*"
loguru = "*"
gunicorn = "*"
feedgen = "*"
[requires]
python_version = "3.7"
python_version = "3"
......@@ -5,7 +5,7 @@ import re
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from functools import lru_cache
from time import mktime, time
from time import time
from typing import Dict, ItemsView
import feedparser
......@@ -13,7 +13,7 @@ from flask import Flask, request, Response
from loguru import logger
from requests.exceptions import RequestException
from requests_html import HTMLSession, HTMLResponse
from werkzeug.contrib.atom import AtomFeed
from feedgen.feed import FeedGenerator
RE_MD_HOTSCORE = re.compile(r"^(\d+)")
RE_MD_ID = re.compile(r"(\d+)$")
......@@ -28,7 +28,7 @@ LWN_PASSWORD = os.environ.get("LWN_PASSWORD")
class Deal:
title: str
url: str
date_published: datetime
date_published: str
_score: int = 0
date_score_updated: datetime = field(default_factory=datetime.now)
price: str = ""
......@@ -102,7 +102,7 @@ class DealzFeed:
self.feed_db[e_id] = Deal(
title=e.title,
url=e.link,
date_published=datetime.fromtimestamp(mktime(e.published_parsed)),
date_published=e.published,
price=e.get("pepper_merchant", {}).get("price", ""),
vendor=e.get("pepper_merchant", {}).get("name", ""),
)
......@@ -189,23 +189,22 @@ def mydealz_feeds(score: int) -> Response:
if not v.isdigit():
return Response(response=f'Parameter "{k}" is not an int!', status=400)
feed = AtomFeed(title="MyDealz", feed_url="1", url="1")
feed = FeedGenerator()
feed.title("MyDealz")
feed.id("https://mydealz.de")
for d_id, d in dealz.get_dealz():
if not d.is_hot(target_score=score, kw_scores=request.args):
continue
e = feed.add_entry()
e.id(str(d_id))
e.title(d.get_title())
e.content(d.content, type="text/html")
e.link(link={"href": d.url})
e.published(d.date_published)
e.updated(d.date_published)
feed.add(
id=d_id,
title=d.get_title(),
content=d.content,
content_type="text/html",
url=d.url,
published=d.date_published,
updated=d.date_published,
)
return feed.get_response()
return feed.atom_str(pretty=True)
def lwn_set_cookie() -> None:
......@@ -232,27 +231,25 @@ def lwn_feeds() -> Response:
lwn_url = "https://lwn.net/headlines/newrss"
f = feedparser.parse(lwn_url)
feed = AtomFeed(title=f.feed.title, feed_url=f.feed.title_detail.base, url=f.url)
for e in f.entries:
content = e.summary
link_url = e.link.replace("/rss", "")
if lwn_is_paid(e.title):
feed = FeedGenerator()
feed.title(f.feed.title)
feed.id("https://lwn.net")
for fe in f.entries:
content = fe.summary
link_url = fe.link.replace("/rss", "")
if lwn_is_paid(fe.title):
content = get_content(link_url, ".ArticleText")
dt = datetime.fromtimestamp(mktime(e.updated_parsed))
feed.add(
id=e.id,
title=e.title,
content=content,
content_type=e.summary_detail.type,
summary=e.summary,
summary_type=e.summary_detail.type,
url=link_url,
published=dt,
updated=dt,
)
return feed.get_response()
e = feed.add_entry()
e.id(fe.id)
e.title(fe.title)
e.content(content, type=fe.summary_detail.type)
e.summary(fe.summary, type=fe.summary_detail.type)
e.link(link={"href": link_url})
e.updated(fe.updated)
return feed.atom_str(pretty=True)
if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment