diff options
-rwxr-xr-x | kadomatsu-rss.py | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/kadomatsu-rss.py b/kadomatsu-rss.py index df1b824..83594c8 100755 --- a/kadomatsu-rss.py +++ b/kadomatsu-rss.py @@ -23,14 +23,6 @@ feed = feedgenerator.Rss201rev2Feed( language="ja", ) - -class Item: - def __init__(self, title, date, content, url): - self.title = title - self.date = date - self.url = url - self.content = content - s = requests.Session() def get_soup(url): @@ -54,39 +46,31 @@ def get_article(url): article = soup.find("li", id="Detail") return format_article(article) -rss_items = [] # god this is a load of fucking spaghetti - -def make_item(i): +def add_article(i): title = list(i.find("a").strings)[0] date = datetime.strptime(i.find("time")["datetime"], "%Y-%m-%d") content_url = relative2absolute(i.find("a")["href"]) - content = format_article(get_article(content_url)) - rss_item = Item(title, date, content, content_url) - rss_items.append(rss_item) + content = get_article(content_url) + feed.add_item( + title=title, + pubdate=date, + link=content_url, + description=content, + ) -def get_rss_items(soup): +def make_feed(soup): items = soup.find("ul", id="List") threads = [] - for i in items.find_all("dl"): - thread = threading.Thread(target=make_item, args=(i,)) + thread = threading.Thread(target=add_article, args=(i,)) threads.append(thread) thread.start() for thread in threads: thread.join() - return rss_items - - -rss_items = get_rss_items(get_soup(root + "?select=all")) -for i in rss_items: - feed.add_item( - title=i.title, - link=i.url, - pubdate=i.date, - description=i.content, - ) +if __name__ == "__main__": + make_feed(get_soup(root + "?select=all")) -print("Content-Type: application/rss+xml; charset=UTF-8") -print() -print(feed.writeString("utf-8")) + print("Content-Type: application/rss+xml; charset=UTF-8") + print() + print(feed.writeString("utf-8")) |