-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
45 lines (37 loc) · 1.1 KB
/
start.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
import feedparser
import socket
import time
#Do not change the values
var = ""
count = 0
#Change the values
server = ""
channel = ""
nick = ""
feed_url = ""
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, 6667))
irc.send(bytes(f"USER {nick} 0 * :{nick}\r\n", "UTF-8"))
irc.send(bytes(f"NICK {nick}\r\n", "UTF-8"))
irc.send(bytes(f"JOIN {channel}\r\n", "UTF-8"))
def Feed(irc):
global var
global feed_url
feed = feedparser.parse(feed_url)
if feed.entries:
latest_article = feed.entries[0]
title = latest_article.title
url = latest_article.link
if title != var:
message = f"Latest Article: {title} - {url}"
irc.send(bytes(f"PRIVMSG {channel} :{message}\r\n", "UTF-8"))
var = title
Feed(irc)
while True:
data = irc.recv(2048).decode("UTF-8")
if "PING" in data:
irc.send(bytes("PONG " + data.split()[1] + "\r\n", "UTF-8"))
count = count + 1 #On libera.chat it seems like PING are sent in intervals of 260 seconds
if count > 2:
Feed(irc)
count = 0