-b = mechanize.Browser()
-b.set_handle_robots(False)
-b.add_client_certificate("https://idp.mit.edu:9443", "cert.pem", "cert.pem")
-b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
-b.open("https://jira.mit.edu/jira/secure/Dashboard.jspa")
-b.follow_link(text="MIT Touchstone")
-b.select_form("wayfForm1")
-b.submit()
-b.select_form(predicate=lambda f: any(c.name == 'login_certificate'
- for c in f.controls))
-b.submit()
-b.select_form(nr=0)
-b.submit()
-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")
-issues_rss = b.response().read()
-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")
-comments_rss = b.response().read()
+def jira_init():
+ b = mechanize.Browser()
+ b.set_handle_robots(False)
+ b.add_client_certificate("https://idp.mit.edu:9443", "cert.pem", "cert.pem")
+ b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
+ return b
+
+def jira_login(b):
+ b.open("https://jira.mit.edu/jira/secure/Dashboard.jspa")
+ try:
+ b.follow_link(text="MIT Touchstone")
+ except mechanize.LinkNotFoundError:
+ return
+ if (urlparse.urlparse(b.geturl())[1] == "jira.mit.edu"):
+ return
+ b.select_form("wayfForm1")
+ b.submit()
+ b.select_form(predicate=lambda f: any(c.name == 'login_certificate'
+ for c in f.controls))
+ b.submit()
+ b.select_form(nr=0)
+ b.submit()
+
+def feed_to_zephyrs(thing, rss, parse):
+ zephyrs = []
+ try:
+ feed = feedparser.parse(rss)
+ for e in feed.entries:
+ global old_time, new_time
+ t = int(calendar.timegm(e.date_parsed))
+ if t <= old_time:
+ continue
+ if t > new_time:
+ new_time = t
+ try:
+ z = parse(e)
+ except:
+ z = zerror("Error parsing " + thing + ":\n" + e.id + "\n" + traceback.format_exc())
+ zephyrs.append((t, z))
+ except:
+ zephyrs.append((0, zerror("Error parsing " + thing + "s feed:\n" + traceback.format_exc())))
+ return zephyrs