mirror of https://github.com/kianby/stacosys
More pythonic singleton with module. Apply pylint recommandations
parent
f231ed1cbb
commit
b1c64d2cc8
@ -1,15 +1,15 @@
|
|||||||
all: black test typehint lint
|
all: black test typehint lint
|
||||||
|
|
||||||
black:
|
black:
|
||||||
isort --multi-line 3 --profile black stacosys/
|
poetry run isort --multi-line 3 --profile black stacosys/
|
||||||
black stacosys/
|
poetry run black stacosys/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pytest
|
poetry run pytest
|
||||||
|
|
||||||
typehint:
|
typehint:
|
||||||
mypy --ignore-missing-imports stacosys/
|
poetry run mypy --ignore-missing-imports stacosys/
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
pylint stacosys/
|
poetry run pylint stacosys/
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,66 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: UTF-8 -*-
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import markdown
|
|
||||||
import PyRSS2Gen
|
|
||||||
|
|
||||||
from stacosys.model.comment import Comment
|
|
||||||
|
|
||||||
|
|
||||||
class Rss:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
lang,
|
|
||||||
rss_file,
|
|
||||||
rss_proto,
|
|
||||||
site_name,
|
|
||||||
site_url,
|
|
||||||
):
|
|
||||||
self._lang = lang
|
|
||||||
self._rss_file = rss_file
|
|
||||||
self._rss_proto = rss_proto
|
|
||||||
self._site_name = site_name
|
|
||||||
self._site_url = site_url
|
|
||||||
|
|
||||||
def generate(self):
|
|
||||||
md = markdown.Markdown()
|
|
||||||
|
|
||||||
items = []
|
|
||||||
for row in (
|
|
||||||
Comment.select()
|
|
||||||
.where(Comment.published)
|
|
||||||
.order_by(-Comment.published)
|
|
||||||
.limit(10)
|
|
||||||
):
|
|
||||||
item_link = "%s://%s%s" % (
|
|
||||||
self._rss_proto,
|
|
||||||
self._site_url,
|
|
||||||
row.url,
|
|
||||||
)
|
|
||||||
items.append(
|
|
||||||
PyRSS2Gen.RSSItem(
|
|
||||||
title="%s - %s://%s%s"
|
|
||||||
% (
|
|
||||||
self._rss_proto,
|
|
||||||
row.author_name,
|
|
||||||
self._site_url,
|
|
||||||
row.url,
|
|
||||||
),
|
|
||||||
link=item_link,
|
|
||||||
description=md.convert(row.content),
|
|
||||||
guid=PyRSS2Gen.Guid("%s/%d" % (item_link, row.id)),
|
|
||||||
pubDate=row.published,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
rss_title = 'Commentaires du site "%s"' % self._site_name
|
|
||||||
rss = PyRSS2Gen.RSS2(
|
|
||||||
title=rss_title,
|
|
||||||
link="%s://%s" % (self._rss_proto, self._site_url),
|
|
||||||
description=rss_title,
|
|
||||||
lastBuildDate=datetime.now(),
|
|
||||||
items=items,
|
|
||||||
)
|
|
||||||
rss.write_xml(open(self._rss_file, "w"), encoding="utf-8")
|
|
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from .configuration import Config
|
||||||
|
from .mail import Mailer
|
||||||
|
from .rssfeed import Rss
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
mailer = Mailer()
|
||||||
|
rss = Rss()
|
@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import markdown
|
||||||
|
import PyRSS2Gen
|
||||||
|
|
||||||
|
from stacosys.model.comment import Comment
|
||||||
|
|
||||||
|
|
||||||
|
class Rss:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self._rss_file: str = ""
|
||||||
|
self._site_proto: str = ""
|
||||||
|
self._site_name: str = ""
|
||||||
|
self._site_url: str = ""
|
||||||
|
|
||||||
|
def configure(
|
||||||
|
self,
|
||||||
|
rss_file,
|
||||||
|
site_proto,
|
||||||
|
site_name,
|
||||||
|
site_url,
|
||||||
|
) -> None:
|
||||||
|
self._rss_file = rss_file
|
||||||
|
self._site_proto = site_proto
|
||||||
|
self._site_name = site_name
|
||||||
|
self._site_url = site_url
|
||||||
|
|
||||||
|
def generate(self) -> None:
|
||||||
|
markdownizer = markdown.Markdown()
|
||||||
|
|
||||||
|
items = []
|
||||||
|
for row in (
|
||||||
|
Comment.select()
|
||||||
|
.where(Comment.published)
|
||||||
|
.order_by(-Comment.published)
|
||||||
|
.limit(10)
|
||||||
|
):
|
||||||
|
item_link = f"{self._site_proto}://{self._site_url}{row.url}"
|
||||||
|
items.append(
|
||||||
|
PyRSS2Gen.RSSItem(
|
||||||
|
title=f"{self._site_proto}://{self._site_url}{row.url} - {row.author_name}",
|
||||||
|
link=item_link,
|
||||||
|
description=markdownizer.convert(row.content),
|
||||||
|
guid=PyRSS2Gen.Guid(f"{item_link}{row.id}"),
|
||||||
|
pubDate=row.published,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
rss_title = f"Commentaires du site {self._site_name}"
|
||||||
|
rss = PyRSS2Gen.RSS2(
|
||||||
|
title=rss_title,
|
||||||
|
link=f"{self._site_proto}://{self._site_url}",
|
||||||
|
description=rss_title,
|
||||||
|
lastBuildDate=datetime.now(),
|
||||||
|
items=items,
|
||||||
|
)
|
||||||
|
# TODO technical debt: replace pyRss2Gen
|
||||||
|
# TODO validate feed (https://validator.w3.org/feed/check.cgi)
|
||||||
|
# pylint: disable=consider-using-with
|
||||||
|
rss.write_xml(open(self._rss_file, "w", encoding="utf-8"), encoding="utf-8")
|
Loading…
Reference in New Issue