16 zephyr_sender = 'jira'
17 zephyr_class = 'andersk-test'
18 time_file = 'jirabot.time'
21 b = mechanize.Browser()
22 b.set_handle_robots(False)
23 b.add_client_certificate("https://idp.mit.edu:9443", "cert.pem", "cert.pem")
24 b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
28 b.open("https://jira.mit.edu/jira/secure/Dashboard.jspa")
29 b.follow_link(text="MIT Touchstone")
30 b.select_form("wayfForm1")
32 b.select_form(predicate=lambda f: any(c.name == 'login_certificate'
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, msg],
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, msg],
73 return zephyr.ZNotice(
77 instance='jira-error',
78 fields=['Jira bot error', msg]
84 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")
85 issues_rss = b.response().read()
86 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")
87 comments_rss = b.response().read()
89 time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8))
92 os.rename(time_file, time_file_new)
96 old_time = int(open(time_file_new).read())
102 for (thing, rss, parse) in [('issue', issues_rss, parse_issue),
103 ('comment', comments_rss, parse_comment)]:
105 feed = feedparser.parse(rss)
106 for e in feed.entries:
107 t = int(calendar.timegm(e.date_parsed))
115 z = zerror("Error parsing " + thing + ":\n" + e.id + "\n" + traceback.format_exc())
116 zephyrs.append((t, z))
118 zephyrs.append((0, zerror("Error parsing " + thing + "s feed:\n" + traceback.format_exc())))
120 open(time_file_new, 'w').write(str(new_time))
122 os.rename(time_file_new, time_file)
124 zephyrs.sort(key=lambda tz: tz[0])
125 for (t, z) in zephyrs: