Randomize the first fetch of watched pages; closing #33
This commit is contained in:
parent
8b819f097d
commit
b184b27d4f
@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import http.client
|
import http.client
|
||||||
import hashlib
|
import hashlib
|
||||||
|
from random import randint
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
@ -27,7 +28,7 @@ def load(context):
|
|||||||
DATAS.setIndex("url", "watch")
|
DATAS.setIndex("url", "watch")
|
||||||
for site in DATAS.getNodes("watch"):
|
for site in DATAS.getNodes("watch"):
|
||||||
if site.hasNode("alert"):
|
if site.hasNode("alert"):
|
||||||
start_watching(site)
|
start_watching(site, randint(-30, 30))
|
||||||
else:
|
else:
|
||||||
print("No alert defined for this site: " + site["url"])
|
print("No alert defined for this site: " + site["url"])
|
||||||
#DATAS.delChild(site)
|
#DATAS.delChild(site)
|
||||||
@ -41,11 +42,11 @@ def getPageContent(url):
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def start_watching(site):
|
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=getPageContent, cmp_data=site["lastcontent"],
|
||||||
func_data=site["url"],
|
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)
|
||||||
site["_evt_id"] = add_event(evt)
|
site["_evt_id"] = add_event(evt)
|
||||||
|
Loading…
Reference in New Issue
Block a user