-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathrss_watch.py
183 lines (167 loc) · 5.53 KB
/
rss_watch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Copyright (C) 2020-2021 by DevsExpo@Github, < https://github.com/DevsExpo >.
#
# This file is part of < https://github.com/DevsExpo/FridayUserBot > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/DevsExpo/blob/master/LICENSE >
#
# All rights reserved.
from main_startup.core.decorators import friday_on_cmd
from main_startup.helper_func.basic_helpers import edit_or_reply, get_text
import feedparser
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from main_startup import Friday
from xtraplugins.dB.rss_db import (
add_rss,
is_get_chat_rss,
del_rss,
get_chat_rss,
update_rss,
basic_check,
get_all,
overall_check,
delete_all
)
@friday_on_cmd(
["add_rss"],
is_official=False,
cmd_help={
"help": "Add RSS To The Chat",
"example": "{ch}add_rss (rss link)",
},
)
async def addrss(client, message):
pablo = await edit_or_reply(message, "`Processing....`")
lenk = get_text(message)
if not lenk:
await pablo.edit("`Please Give Me A Valid Input. You Can Check Help Menu To Know More!`")
return
try:
rss_d = feedparser.parse(lenk)
rss_d.entries[0].title
except:
await pablo.edit("ERROR: The link does not seem to be a RSS feed or is not supported")
return
lol = await is_get_chat_rss(message.chat.id, lenk)
if lol:
await pablo.edit("This Link Already Added")
return
content = ""
content += f"**{rss_d.entries[0].title}**"
content += f"\n\n{rss_d.entries[0].link}"
try:
content += f"\n{rss_d.entries[0].description}"
except:
pass
await client.send_message(message.chat.id, content)
await add_rss(message.chat.id, lenk, rss_d.entries[0].link)
await pablo.edit("Successfully Added Link To RSS Watch")
@friday_on_cmd(
["test_rss"],
is_official=False,
cmd_help={
"help": "Test RSS Of The Chat",
"example": "{ch}test_rss",
},
)
async def testrss(client, message):
pablo = await edit_or_reply(message, "`Processing....`")
damn = await basic_check(message.chat.id)
if not damn:
URL = "https://www.reddit.com/r/funny/new/.rss"
rss_d = feedparser.parse(URL)
Content = (rss_d.entries[0]['title'] + "\n\n" + rss_d.entries[0]['link'])
await client.send_message(message.chat.id, Content)
await pablo.edit("This Chat Has No RSS So Sent Reddit RSS")
else:
all = await get_chat_rss(message.chat.id)
for x in all:
link = x.get("rss_link")
rss_d = feedparser.parse(link)
content = ""
content += f"**{rss_d.entries[0].title}**"
content += f"\n\nLink : {rss_d.entries[0].link}"
try:
content += f"\n{rss_d.entries[0].description}"
except:
pass
await client.send_message(message.chat.id, content)
await pablo.delete()
@friday_on_cmd(
["list_rss"],
is_official=False,
cmd_help={
"help": "List all RSS Of The Chat",
"example": "{ch}list_rss",
},
)
async def listrss(client, message):
pablo = await edit_or_reply(message, "`Processing....`")
damn = await basic_check(message.chat.id)
if not damn:
await pablo.edit("This Chat Has No RSS!")
return
links = ""
all = await get_chat_rss(message.chat.id)
for x in all:
l = x.get("rss_link")
links += f"{l}\n"
content = f"Rss Found In The Chat Are : \n\n{links}"
await client.send_message(message.chat.id, content)
await pablo.delete()
@friday_on_cmd(
["del_rss"],
is_official=False,
cmd_help={
"help": "Delete RSS From The Chat",
"example": "{ch}del_rss (rss link)",
},
)
async def delrss(client, message):
pablo = await edit_or_reply(message, "`Processing....`")
lenk = get_text(message)
if not lenk:
await pablo.edit("`Please Give Me A Valid Input. You Can Check Help Menu To Know More!`")
return
lol = await is_get_chat_rss(message.chat.id, lenk)
if not lol:
await pablo.edit("This Link Was Never Added")
return
await del_rss(message.chat.id, lenk)
await pablo.edit(f"Successfully Removed `{lenk}` From Chat RSS")
@friday_on_cmd(
["del_all_rss", "rm_all_rss"],
is_official=False,
cmd_help={
"help": "Deletes All RSS From The Chat",
"example": "{ch}del_all_rss",
},
)
async def delrss(client, message):
pablo = await edit_or_reply(message, "`Processing....`")
if not await basic_check(message.chat.id):
await pablo.edit("This Chat Has No RSS To Delete")
return
await delete_all()
await pablo.edit("Successfully Deleted All RSS From The Chat")
async def check_rss():
if not await overall_check():
return
all = await get_all()
for one in all:
link = one.get("rss_link")
old = one.get("latest_rss")
rss_d = feedparser.parse(link)
if rss_d.entries[0].link != old:
message = one.get("chat_id")
content = ""
content += f"**{rss_d.entries[0].title}**"
content += f"\n\nLink : {rss_d.entries[0].link}"
try:
content += f"\n{rss_d.entries[0].description}"
except:
pass
await update_rss(message, link, rss_d.entries[0].link)
await Friday.send_message(message, content)
scheduler = AsyncIOScheduler()
scheduler.add_job(check_rss, 'interval', minutes=10)
scheduler.start()