summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2016-07-04 10:33:13 -0400
committerFélix Sipma <felix.sipma@no-log.org>2016-07-04 10:34:19 -0400
commit126b7b4d291245f7e11b671a697c57d678c8cae6 (patch)
treec0cdfa448057f7757fea998e8e9ab435853110c9
parentb39cb74f76d26bc73e83874ad49950f5075bc452 (diff)
add POST with data
-rwxr-xr-xwebdiff17
1 files changed, 10 insertions, 7 deletions
diff --git a/webdiff b/webdiff
index 1d955fb..f9a67f8 100755
--- a/webdiff
+++ b/webdiff
@@ -97,6 +97,7 @@ an url field. All the other fiels are optional.
[webpage] section:
url: url to check (required)
+ data: use POST instead of GET with data (default: ignored)
interval (default: see [general] section)
block_from: first match (after applying format_html_command) of block_from
will delimit the beginning of the content block (default: ignored)
@@ -208,7 +209,8 @@ def block_filter(content, block_from, block_to, block_skip):
return content
-def check_url(url, timeout, block_from, block_to, block_skip, format_html):
+def check_url(url, data, timeout, block_from, block_to, block_skip,
+ format_html):
"""
Returns content and last check datetime of a given url.
"""
@@ -216,7 +218,7 @@ def check_url(url, timeout, block_from, block_to, block_skip, format_html):
html_content = ""
while True:
try:
- response = opener.open(url, timeout=timeout)
+ response = opener.open(url, data=data, timeout=timeout)
html_content = response.read()
except Exception as error:
if retry >= 3:
@@ -253,7 +255,7 @@ def diff(old_list, new_list, old_title, new_title):
return difflib.unified_diff(old_list, new_list, old_title, new_title)
-def check_page(url, timeout, interval, block_from, block_to, block_skip,
+def check_page(url, data, timeout, interval, block_from, block_to, block_skip,
format_html):
"""
call check_url if interval is exceed.
@@ -261,8 +263,8 @@ def check_page(url, timeout, interval, block_from, block_to, block_skip,
query = session.query(Page).filter_by(url=url)
output = None
if query.all() == []:
- content, last_check = check_url(url, timeout, block_from, block_to,
- block_skip, format_html)
+ content, last_check = check_url(url, data, timeout, block_from,
+ block_to, block_skip, format_html)
page = Page()
page.url = url
page.content = content
@@ -275,7 +277,7 @@ def check_page(url, timeout, interval, block_from, block_to, block_skip,
page = query[0]
old_last_check = page.last_check
if now() - old_last_check > datetime.timedelta(minutes=interval):
- content, last_check = check_url(url, timeout, block_from,
+ content, last_check = check_url(url, data, timeout, block_from,
block_to, block_skip, format_html)
output = diff(page.content, content,
old_last_check, last_check)
@@ -339,6 +341,7 @@ if __name__ == "__main__":
for section in conffile.sections():
if section != 'general':
url = conffile.get(section, 'url')
+ data = option_or_default(section, 'data', None)
timeout = int(option_or_default(section, 'timeout',
global_timeout))
interval = int(option_or_default(section, 'interval',
@@ -349,7 +352,7 @@ if __name__ == "__main__":
global_block_skip))
format_html = option_or_default(section, 'format_html_command',
global_format_html)
- page, output = check_page(url=url, timeout=timeout,
+ page, output = check_page(url=url, data=data, timeout=timeout,
interval=interval,
block_from=block_from, block_to=block_to,
block_skip=block_skip,