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")
30 b
.follow_link(text
="MIT Touchstone")
31 except mechanize
.LinkNotFoundError
:
33 if (urlparse
.urlparse(b
.geturl())[1] == "jira.mit.edu"):
35 b
.select_form("wayfForm1")
37 b
.select_form(predicate
=lambda f
: any(c
.name
== 'login_certificate'
43 def feed_to_zephyrs(thing
, rss
, parse
):
46 feed
= feedparser
.parse(rss
)
47 for e
in feed
.entries
:
48 global old_time
, new_time
49 t
= int(calendar
.timegm(e
.date_parsed
))
57 z
= zerror("Error parsing " + thing
+ ":\n" + e
.id + "\n" + traceback
.format_exc())
58 zephyrs
.append((t
, z
))
60 zephyrs
.append((0, zerror("Error parsing " + thing
+ "s feed:\n" + traceback
.format_exc())))
64 issue
= urlparse
.urlparse(e
.id)[2].rsplit('/', 1)[1]
66 msg
= e
.id + "\nThis issue was updated."
68 return zephyr
.ZNotice(
73 fields
=[e
.title
, msg
],
77 url
= urlparse
.urlunsplit(urlparse
.urlparse(e
.id)[0:3] + (None,None))
78 issue
= url
.rsplit('/', 1)[1]
80 s
= cStringIO
.StringIO()
81 parser
= htmllib
.HTMLParser(formatter
.AbstractFormatter(formatter
.DumbWriter(s
)))
82 parser
.feed(e
.summary
.rsplit('<table>', 1)[0])
87 msg
= e
.author
+ " added a comment:\n" + comment
.rstrip()
89 return zephyr
.ZNotice(
94 fields
=[e
.title
, msg
],
98 return zephyr
.ZNotice(
102 instance
='jira-error',
103 fields
=['Jira bot error', msg
]
111 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")
112 issues_rss
= b
.response().read()
113 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")
114 comments_rss
= b
.response().read()
116 time_file_new
= time_file
+ '.' + ''.join(random
.sample(string
.letters
, 8))
119 os
.rename(time_file
, time_file_new
)
123 old_time
= int(open(time_file_new
).read())
126 zephyrs
= (feed_to_zephyrs('issue', issues_rss
, parse_issue
) +
127 feed_to_zephyrs('comment', comments_rss
, parse_comment
))
129 open(time_file_new
, 'w').write(str(new_time
))
131 os
.rename(time_file_new
, time_file
)
133 zephyrs
.sort(key
=lambda tz
: tz
[0])
134 for (t
, z
) in zephyrs
: