16 zephyr_sender = 'jira'
17 zephyr_class = 'andersk-test'
18 time_file = 'jirabot.time'
20 b = mechanize.Browser()
21 b.set_handle_robots(False)
22 b.add_client_certificate("https://idp.mit.edu:9443", "cert.pem", "cert.pem")
23 b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
24 b.open("https://jira.mit.edu/jira/secure/Dashboard.jspa")
25 b.follow_link(text="MIT Touchstone")
26 b.select_form("wayfForm1")
28 b.select_form(predicate=lambda f: any(c.name == 'login_certificate'
33 b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
34 issues_rss = b.response().read()
35 b.open("https://jira.mit.edu/jira/sr/jira.issueviews:searchrequest-comments-rss/temp/SearchRequest.xml?&pid=10185&updated%3Aprevious=-1w&sorter/field=updated&sorter/order=DESC&tempMax=1000")
36 comments_rss = b.response().read()
39 issue = urlparse.urlparse(e.id)[2].rsplit('/', 1)[1]
41 msg = e.id + "\nThis issue was updated."
43 return zephyr.ZNotice(
48 fields=[e.title.encode('UTF-8'), msg.encode('UTF-8')],
52 url = urlparse.urlunsplit(urlparse.urlparse(e.id)[0:3] + (None,None))
53 issue = url.rsplit('/', 1)[1]
55 s = cStringIO.StringIO()
56 parser = htmllib.HTMLParser(formatter.AbstractFormatter(formatter.DumbWriter(s)))
57 parser.feed(e.summary.rsplit('<table>', 1)[0])
62 msg = e.author + " added a comment:\n" + comment.rstrip()
64 return zephyr.ZNotice(
69 fields=[e.title.encode('UTF-8'), msg.encode('UTF-8')],
75 return zephyr.ZNotice(
79 instance='jira-error',
80 fields=['Jira bot error', msg.encode('UTF-8')]
83 time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8))
86 os.rename(time_file, time_file_new)
90 old_time = int(open(time_file_new).read())
96 for (thing, rss, parse) in [('issue', issues_rss, parse_issue),
97 ('comment', comments_rss, parse_comment)]:
99 feed = feedparser.parse(rss)
100 for e in feed.entries:
101 t = int(calendar.timegm(e.date_parsed))
109 z = zerror("Error parsing " + thing + ":\n" + e.id + "\n" + traceback.format_exc())
110 zephyrs.append((t, z))
112 zephyrs.append((0, zerror("Error parsing " + thing + "s feed:\n" + traceback.format_exc())))
114 open(time_file_new, 'w').write(str(new_time))
116 os.rename(time_file_new, time_file)
118 zephyrs.sort(key=lambda tz: tz[0])
119 for (t, z) in zephyrs: