From 8b8cecc4126ff4b0e25b0a96155028352993b8af Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 13 Feb 2009 03:47:15 -0500 Subject: [PATCH] Make initialization and login into functions. --- jirabot.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/jirabot.py b/jirabot.py index 15ca631..9d36e91 100755 --- a/jirabot.py +++ b/jirabot.py @@ -17,23 +17,23 @@ zephyr_sender = 'jira' zephyr_class = 'andersk-test' time_file = 'jirabot.time' -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") + 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() def parse_issue(e): issue = urlparse.urlparse(e.id)[2].rsplit('/', 1)[1] @@ -78,6 +78,14 @@ def zerror(msg): fields=['Jira bot error', msg] ) +b = jira_init() + +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() + time_file_new = time_file + '.' + ''.join(random.sample(string.letters, 8)) try: -- 2.45.1