From dda8cd7485649eec0c70fe51ff271e1afbb478a7 Mon Sep 17 00:00:00 2001 From: Apocalypsor <37431235+Apocalypsor@users.noreply.github.com> Date: Thu, 27 May 2021 22:14:43 +0800 Subject: [PATCH] Update --- FR2T/fr2t.py | 28 ++++++++++++++++------------ test/rss.py | 10 +++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/FR2T/fr2t.py b/FR2T/fr2t.py index 99ee8d7..f684eb1 100644 --- a/FR2T/fr2t.py +++ b/FR2T/fr2t.py @@ -1,17 +1,19 @@ -from .parser import rssParser, objParser -from .utils import postData, escapeAll, escapeText -from jinja2 import Template -from pymongo import MongoClient +import copy +import copyreg import datetime import hashlib -import time -import re -import yaml -from multiprocessing import Pool -import ssl -import copyreg -import copy import os +import re +import ssl +import time +from multiprocessing import Pool + +import yaml +from jinja2 import Template +from pymongo import MongoClient + +from .parser import rssParser, objParser +from .utils import postData, escapeAll, escapeText class FR2T: @@ -181,7 +183,9 @@ def handleRSS(rss, url, telegram, db, user_agent): if send: template = Template(rss["text"]) - args = dict(**result, **content, rss_name=rss["name"], rss_url=rss["url"]) + args = dict( + **result, **content, rss_name=rss["name"], rss_url=rss["url"] + ) escapeAll(telegram["parse_mode"], args) text = template.render(args) diff --git a/test/rss.py b/test/rss.py index 09393e8..22a407b 100644 --- a/test/rss.py +++ b/test/rss.py @@ -1,19 +1,23 @@ -import feedparser import json -import sys import os +import sys +import feedparser my_path = __file__ my_direc = os.path.dirname(__file__) -def parseUrl(url: str="https://github.com/Apocalypsor/Formatted-RSS-to-Telegram/commits/main.atom"): + +def parseUrl( + url: str = "https://github.com/Apocalypsor/Formatted-RSS-to-Telegram/commits/main.atom", +): d = feedparser.parse(url)["entries"] file_name = url.replace("https://", "").replace("http://", "").replace("/", "_") with open(os.path.join(my_direc, f"{file_name}.json"), "w", encoding="UTF-8") as t: json.dump(d, t, indent=4, ensure_ascii=False) + if __name__ == "__main__": if len(sys.argv) == 1: parseUrl()