Conditions | 5 |
Total Lines | 22 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # -*- encoding: utf-8 -*- |
||
16 | def main(self): |
||
17 | self.remove_old_history() |
||
18 | rss_list = Rss.select() |
||
19 | msg = "" |
||
20 | post_url_list = [ |
||
21 | rss_history.url |
||
22 | for rss_history in History.select().where( |
||
23 | History.publish_at == datetime.today().strftime("%Y-%m-%d") |
||
24 | ) |
||
25 | ] |
||
26 | for rss in rss_list: |
||
27 | rss_history_list = [] |
||
28 | feed = feedparser.parse(rss.feed) |
||
29 | for entry in feed.entries: |
||
30 | if entry.link not in post_url_list: |
||
31 | msg = msg + f"{entry.title}\n{entry.link}\n\n" |
||
32 | rss_history_list.append(History(url=entry.link)) |
||
33 | |||
34 | with db.atomic(): |
||
35 | History.bulk_create(rss_history_list, batch_size=10) |
||
36 | |||
37 | return msg |
||
38 | |||
50 |