Add a connection with musik.p0m.fr
Fix parse error when parsing dates in 42.xml Increase stability with try/expect
This commit is contained in:
parent
ada5b0eeeb
commit
448b455e77
6 changed files with 78 additions and 6 deletions
13
atom.py
13
atom.py
|
@ -10,9 +10,20 @@ class AtomEntry:
|
||||||
def __init__ (self, node):
|
def __init__ (self, node):
|
||||||
self.id = node.getElementsByTagName("id")[0].firstChild.nodeValue
|
self.id = node.getElementsByTagName("id")[0].firstChild.nodeValue
|
||||||
self.title = node.getElementsByTagName("title")[0].firstChild.nodeValue
|
self.title = node.getElementsByTagName("title")[0].firstChild.nodeValue
|
||||||
self.updated = time.strptime(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:19], "%Y-%m-%dT%H:%M:%S")
|
try:
|
||||||
|
self.updated = time.strptime(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:19], "%Y-%m-%dT%H:%M:%S")
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
self.updated = time.strptime(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10], "%Y-%m-%d")
|
||||||
|
except:
|
||||||
|
print (node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10])
|
||||||
|
self.updated = time.localtime ()
|
||||||
self.summary = node.getElementsByTagName("summary")[0].firstChild.nodeValue
|
self.summary = node.getElementsByTagName("summary")[0].firstChild.nodeValue
|
||||||
self.link = node.getElementsByTagName("link")[0].getAttribute ("href")
|
self.link = node.getElementsByTagName("link")[0].getAttribute ("href")
|
||||||
|
if len (node.getElementsByTagName("link")) > 1:
|
||||||
|
self.link2 = node.getElementsByTagName("link")[1].getAttribute ("href")
|
||||||
|
else:
|
||||||
|
self.link2 = None
|
||||||
|
|
||||||
class Atom:
|
class Atom:
|
||||||
def __init__ (self, string):
|
def __init__ (self, string):
|
||||||
|
|
|
@ -10,7 +10,7 @@ from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
|
|
||||||
imports = ["birthday", "qd", "events"]
|
imports = ["birthday", "qd", "events", "youtube"]
|
||||||
imports_launch = ["watchWebsite"]
|
imports_launch = ["watchWebsite"]
|
||||||
mods = list ()
|
mods = list ()
|
||||||
import server
|
import server
|
||||||
|
|
4
qd.py
4
qd.py
|
@ -32,8 +32,8 @@ def xmlparse(node):
|
||||||
manche.getAttribute("winner"),
|
manche.getAttribute("winner"),
|
||||||
int(manche.getAttribute("winner_score")),
|
int(manche.getAttribute("winner_score")),
|
||||||
manche.getAttribute("who"),
|
manche.getAttribute("who"),
|
||||||
datetime.now ())
|
# datetime.now ())
|
||||||
# time.strptime (manche.getAttribute("date")))
|
datetime.fromtimestamp (time.mktime (time.strptime (manche.getAttribute("date")[:19], "%Y-%m-%d %H:%M:%S"))))
|
||||||
|
|
||||||
def load_module(datas_path):
|
def load_module(datas_path):
|
||||||
"""Load this module"""
|
"""Load this module"""
|
||||||
|
|
11
server.py
11
server.py
|
@ -46,13 +46,20 @@ class Server:
|
||||||
def read(self, mods):
|
def read(self, mods):
|
||||||
self.readbuffer = "" #Here we store all the messages from server
|
self.readbuffer = "" #Here we store all the messages from server
|
||||||
while 1:
|
while 1:
|
||||||
self.readbuffer = self.readbuffer + self.s.recv(1024).decode() #recieve server messages
|
try:
|
||||||
|
self.readbuffer = self.readbuffer + self.s.recv(1024).decode() #recieve server messages
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
print ("ERREUR de décodage unicode")
|
||||||
|
continue
|
||||||
temp = self.readbuffer.split("\n")
|
temp = self.readbuffer.split("\n")
|
||||||
self.readbuffer = temp.pop( )
|
self.readbuffer = temp.pop( )
|
||||||
|
|
||||||
for line in temp:
|
for line in temp:
|
||||||
msg = message.Message (self, line)
|
msg = message.Message (self, line)
|
||||||
msg.treat (mods)
|
try:
|
||||||
|
msg.treat (mods)
|
||||||
|
except:
|
||||||
|
print ("Une erreur est survenue lors du traitement du message : %s"%line)
|
||||||
|
|
||||||
|
|
||||||
def connect(self, mods):
|
def connect(self, mods):
|
||||||
|
|
|
@ -10,6 +10,7 @@ from xml.dom.minidom import parseString
|
||||||
from xml.dom.minidom import getDOMImplementation
|
from xml.dom.minidom import getDOMImplementation
|
||||||
|
|
||||||
import atom
|
import atom
|
||||||
|
import youtube
|
||||||
|
|
||||||
filename = ""
|
filename = ""
|
||||||
SITES = []
|
SITES = []
|
||||||
|
@ -67,6 +68,9 @@ def treat_atom (lastpage, content, message):
|
||||||
else:
|
else:
|
||||||
messageI = message % ("quel est ce nouveau fichier", "%s")
|
messageI = message % ("quel est ce nouveau fichier", "%s")
|
||||||
send_global (messageI % unquote (d.link))
|
send_global (messageI % unquote (d.link))
|
||||||
|
elif f.id == "http://musik.p0m.fr/atom.php?nemubot":
|
||||||
|
for d in diff:
|
||||||
|
youtube.send_global (d.link2, message % (d.title, unquote (d.link)))
|
||||||
elif message.find ("%s") >= 0:
|
elif message.find ("%s") >= 0:
|
||||||
for d in diff:
|
for d in diff:
|
||||||
send_global (message % unquote (d.link))
|
send_global (message % unquote (d.link))
|
||||||
|
|
50
youtube.py
Normal file
50
youtube.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
import re
|
||||||
|
import http.client
|
||||||
|
|
||||||
|
URLS = dict ()
|
||||||
|
|
||||||
|
def load_module(datas_path):
|
||||||
|
"""Load this module"""
|
||||||
|
global URLS
|
||||||
|
URLS = dict ()
|
||||||
|
|
||||||
|
def save_module():
|
||||||
|
"""Save the dates"""
|
||||||
|
return
|
||||||
|
|
||||||
|
def help_tiny ():
|
||||||
|
"""Line inserted in the response to the command !help"""
|
||||||
|
return
|
||||||
|
|
||||||
|
def help_full ():
|
||||||
|
return
|
||||||
|
|
||||||
|
def parseanswer(msg):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def parseask(msg):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def parselisten (msg):
|
||||||
|
global URLS
|
||||||
|
matches = [".*(http://(www\.)?youtube.com/watch\?v=([a-zA-Z0-9_-]{11})).*",
|
||||||
|
".*(http://(www\.)?youtu.be/([a-zA-Z0-9_-]{11})).*"]
|
||||||
|
for m in matches:
|
||||||
|
res = re.match (m, msg.content)
|
||||||
|
if res is not None:
|
||||||
|
#print ("seen : %s"%res.group(1))
|
||||||
|
URLS[res.group(1)] = msg
|
||||||
|
conn = http.client.HTTPConnection("musik.p0m.fr")
|
||||||
|
conn.request("GET", "/?nemubot&a=add&url=%s"%(res.group (1)))
|
||||||
|
conn.getresponse()
|
||||||
|
conn.close()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def send_global (origin, msg):
|
||||||
|
if origin in URLS:
|
||||||
|
URLS[origin].send_chn (msg)
|
||||||
|
del URLS[origin]
|
Loading…
Add table
Add a link
Reference in a new issue