WatchWebsite module: use w3m function from networking module

This commit is contained in:
nemunaire 2014-09-20 00:15:06 +02:00
parent 7a5c2d9786
commit a7830f709d

View File

@ -12,10 +12,10 @@ import socket
import sys import sys
import urllib.parse import urllib.parse
from urllib.parse import urlparse from urllib.parse import urlparse
from urllib.request import urlopen
from hooks import hook from hooks import hook
from networking import w3m
from .atom import Atom from .atom import Atom
nemubotversion = 3.4 nemubotversion = 3.4
@ -33,19 +33,10 @@ def load(context):
print("No alert defined for this site: " + site["url"]) print("No alert defined for this site: " + site["url"])
#DATAS.delChild(site) #DATAS.delChild(site)
def getPageContent(url):
"""Returns the content of the given url"""
print_debug("Get page %s" % url)
try:
raw = urlopen(url, timeout=10)
return raw.read().decode()
except:
return None
def start_watching(site, offset=0): def start_watching(site, offset=0):
o = urlparse(site["url"], "http") o = urlparse(site["url"], "http")
print_debug("Add event for site: %s" % o.netloc) print_debug("Add event for site: %s" % o.netloc)
evt = ModuleEvent(func=getPageContent, cmp_data=site["lastcontent"], evt = ModuleEvent(func=lambda url: w3m(url), cmp_data=site["lastcontent"],
func_data=site["url"], offset=offset, func_data=site["url"], offset=offset,
intervalle=site.getInt("time"), intervalle=site.getInt("time"),
call=alert_change, call_data=site) call=alert_change, call_data=site)