]> andersk Git - jira-zephyrbot.git/commitdiff
More implementations.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Wed, 11 Feb 2009 08:06:04 +0000 (03:06 -0500)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Wed, 11 Feb 2009 08:06:04 +0000 (03:06 -0500)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
jirabot.py
jirabot2.py [new file with mode: 0644]
urllib-cert.py [new file with mode: 0644]

index bf055170992d28211addd658b2769aa6e6536ec4..45eeb4d546899f0fbeb6d4f274a2786f78bbc0fa 100644 (file)
@@ -1,6 +1,7 @@
 import zephyr
 import feedparser
 import pycurl
+from BeautifulSoup import BeautifulSoup
 
 """Screen scrapes jira.mit.edu. Supposedly. Doesn't actually work yet.
 
@@ -30,6 +31,27 @@ class Browser(object):
         self.lastResult = ''
         c.perform()
         return self.lastResult
+    def getPage(self, url):
+        return Page(url, self.get(url), self)
+
+class Page(object):
+    def __init__(self, url, contents, browser):
+        self.url = url
+        self.soup = BeautifulSoup(contents)
+        self.browser = browser
+    def submitForm(self, name, args ={}):
+        form = self.soup.find(name='form', attrs={"name": name})
+        if form == None: return False
+        dest = form.get('action', self.url)
+        # this has a lot of edge-cases that don't work
+        inputs = form.findAll(name='input')
+        vals = {}
+        for input in inputs:
+            vals[input[name]] = input[value]
+        for k,v in args.items():
+            vals[k] = v
+        return self.browser.getPage()
+
 
 b = Browser(
     SSLCERT = "cert.pem",
@@ -37,10 +59,14 @@ b = Browser(
     SSL_VERIFYPEER = 0,
     COOKIEJAR = "jirabot.cookie",
     FOLLOWLOCATION = 1,
+    AUTOREFERER = 1,
+    HTTPHEADER = ["Accept-Language: en-us,en;q=0.5"],
 )
 
 b.get("https://jira.mit.edu/jira/secure/Dashboard.jspa")
-print b.get("https://jira.mit.edu/jira/secure/mit_login.jsp?os_destination=/secure/Dashboard.jspa")
+page = b.getPage("https://jira.mit.edu/jira/secure/mit_login.jsp?os_destination=/secure/Dashboard.jspa")
+
+print page.submitForm('wayfForm1')
 
 #c.setopt(c.URL, "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")
 
diff --git a/jirabot2.py b/jirabot2.py
new file mode 100644 (file)
index 0000000..9e66d8e
--- /dev/null
@@ -0,0 +1,30 @@
+import httplib
+import mechanize
+
+def make_cert_handler(key_file=None, cert_file=None):
+    if cert_file is None:
+        cert_file = key_file
+
+    class HTTPSCertConnection(httplib.HTTPSConnection):
+        def __init__(self, host):
+            httplib.HTTPSConnection.__init__(self, host,
+                                             key_file=key_file,
+                                             cert_file=cert_file)
+
+    class HTTPSCertHandler(mechanize.HTTPSHandler):
+        def https_open(self, req):
+            return self.do_open(HTTPSCertConnection, req)
+
+    return HTTPSCertHandler
+
+cj = mechanize.CookieJar()
+
+cert_handler = make_cert_handler("cert.pem")
+opener = mechanize.build_opener(mechanize.HTTPRedirectHandler, cert_handler, mechanize.HTTPCookieProcessor(cj))
+mechanize.install_opener(opener)
+
+b = mechanize.Browser()
+b.set_handle_robots(False)
+b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
+b.open("https://jira.mit.edu/jira/secure/Dashboard.jsp://jira.mit.edu/jira/secure/Dashboard.jspa")
+b.follow_link(text="MIT Touchstone")
diff --git a/urllib-cert.py b/urllib-cert.py
new file mode 100644 (file)
index 0000000..3781026
--- /dev/null
@@ -0,0 +1,26 @@
+import urllib2
+import httplib
+
+cert_file = "cert.pem"
+key_file = cert_file
+
+class HTTPSCertConnection(httplib.HTTPSConnection):
+    def __init__(self, host):
+        httplib.HTTPSConnection.__init__(self, host, None, key_file, cert_file)
+
+class HTTPSCertHandler(urllib2.HTTPSHandler):
+    def do_open(self, http_class, req):
+        if http_class is httplib.HTTPSConnection:
+            http_class = HTTPSCertConnection
+        return urllib2.HTTPSHandler.do_open(self, http_class, req)
+
+opener = urllib2.build_opener(urllib2.HTTPRedirectHandler, HTTPSCertHandler)
+urllib2.install_opener(opener)
+
+#req = urllib2.Request(url='https://geofft.scripts.mit.edu:444/detect.php')
+#f = urllib2.urlopen(req)
+#print f.read()
+
+req = urllib2.Request(url='https://jira.mit.edu/jira/secure/mit_login.jsp?os_destination=/secure/Dashboard.jspa')
+print urllib2.urlopen(req).read()
+
This page took 0.331391 seconds and 5 git commands to generate.