#!/usr/bin/python
-import cStringIO
import calendar
import feedparser
import formatter
+import htmlentitydefs
import htmllib
import mechanize
import os
import random
import string
+import StringIO
import time
import traceback
import urlparse
zephyr_class = 'andersk-test'
time_file = 'jirabot.time'
+class UnicodeHTMLParser(htmllib.HTMLParser):
+ entitydefs = dict((k, unichr(v)) for (k, v) in htmlentitydefs.name2codepoint.items())
+
+ def convert_charref(self, name):
+ try:
+ n = int(name)
+ except ValueError:
+ return
+ return self.convert_codepoint(n)
+
+ def convert_codepoint(self, codepoint):
+ return unichr(codepoint)
+
def jira_init():
b = mechanize.Browser()
b.set_handle_robots(False)
url = urlparse.urlunsplit(urlparse.urlparse(e.id)[0:3] + (None,None))
issue = url.rsplit('/', 1)[1]
- s = cStringIO.StringIO()
- parser = htmllib.HTMLParser(formatter.AbstractFormatter(formatter.DumbWriter(s)))
+ s = StringIO.StringIO()
+ parser = UnicodeHTMLParser(formatter.AbstractFormatter(formatter.DumbWriter(s)))
parser.feed(e.summary.rsplit('<table>', 1)[0])
parser.close()
- s.seek(0)
- comment = s.read()
+ comment = s.getvalue()
msg = e.author + " added a comment:\n" + comment.rstrip()
b = jira_init()
zephyr.init()
+count = 0
+
while True:
time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8))
time.sleep(17)
continue
+ if (count >= 200):
+ b = jira_init()
+ count = 0
+ count += 1
+
jira_login(b)
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()
+ b.clear_history()
old_time = int(open(time_file_new).read())
new_time = old_time
open(time_file_new, 'w').write(str(new_time))
os.rename(time_file_new, time_file)
- time.sleep(60)
+ time.sleep(20)