Commit 5eaf6615 authored by Marco Mariani's avatar Marco Mariani

fix for multiple notifications

parent 8f16692d
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import math import argparse
import subprocess
import os
import uuid
import csv import csv
import time
import urllib2
from urlparse import urlparse
import httplib import httplib
import math
import os
import socket import socket
import subprocess
import sys import sys
import argparse import time
import urllib2
import urlparse
import uuid
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
...@@ -61,8 +62,11 @@ def main(): ...@@ -61,8 +62,11 @@ def main():
]) ])
feed = urllib2.urlopen(args.feed_url[0]) feed = urllib2.urlopen(args.feed_url[0])
body = feed.read()
failed = False
for notif_url in args.notification_url: for notif_url in args.notification_url:
notification_url = urlparse(notif_url) notification_url = urlparse.urlparse(notif_url)
notification_port = notification_url.port notification_port = notification_url.port
if notification_port is None: if notification_port is None:
notification_port = socket.getservbyname(notification_url.scheme) notification_port = socket.getservbyname(notification_url.scheme)
...@@ -70,14 +74,17 @@ def main(): ...@@ -70,14 +74,17 @@ def main():
headers = {'Content-Type': feed.info().getheader('Content-Type')} headers = {'Content-Type': feed.info().getheader('Content-Type')}
notification = httplib.HTTPConnection(notification_url.hostname, notification = httplib.HTTPConnection(notification_url.hostname,
notification_port) notification_port)
notification.request('POST', notification_url.path, feed.read(), headers) notification.request('POST', notification_url.path, body, headers)
response = notification.getresponse() response = notification.getresponse()
if not (200 <= response.status < 300): if not (200 <= response.status < 300):
print >> sys.stderr, "The remote server didn't send a successfull reponse." sys.stderr.write("The remote server at %s didn't send a successful reponse.\n" % notif_url)
print >> sys.stderr, "It's response was %r" % response.reason sys.stderr.write("Its response was %r\n" % response.reason)
return 1 failed = True
return 0
if failed:
sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment