Changeset 35 for launchpad_test.py

Show
Ignore:
Timestamp:
07/10/06 16:22:28 (2 years ago)
Author:
ploum
Message:

You can now import a bookmark file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • launchpad_test.py

    r20 r35  
    44import gobject 
    55import gtk.glade 
    6 import urllib 
     6import urllib, urllib2, mechanize, cookielib 
     7import ClientForm 
    78from bug import * 
    89from BeautifulSoup import BeautifulSoup 
    910# You have to change this if you have another storage 
    10 from auth_dummy import user 
     11#from auth_dummy import user 
     12 
     13zeurl="https://staging.launchpad.net/bugs/51835" 
     14base_url = "https://staging.launchpad.net/" 
     15 
     16cookies = cookielib.CookieJar() 
     17req = urllib2.Request("https://staging.launchpad.net/") 
     18resp = urllib2.urlopen(req) 
     19cookies.extract_cookies(resp, req) 
     20 
     21def login(username, password): 
     22        data = {'form': 'login', 
     23                'loginpage_email': username, 
     24                'loginpage_password': password, 
     25                'loginpage_submit_login': 'Log In'} 
     26        url = base_url + 'products/+login' 
     27        fetch(url, data) 
     28 
     29def fetch(url, data): 
     30        postdata = urllib.urlencode(data) 
     31        req = urllib2.Request(url, postdata) 
     32        c = cookies._cookies_for_request(req)[0] 
     33        req.add_header('Cookie', '%s=%s' % (c.name, c.value)) 
     34        #print c.value 
     35        return urllib2.urlopen(req).read() 
     36 
     37#editurl="to_get" 
     38login("","") 
     39#request= mecha.Request(zeurl) 
     40data={ 'field.status' : 'Rejected', 
     41                'FORM_SUBMIT' : 'Save Changes'} 
     42f= fetch(zeurl, data) 
     43print f 
     44 
     45#forms = ClientForm.ParseResponse(f, backwards_compat=False) 
     46#for i in forms : 
     47#       print i 
    1148 
    1249 
    13 zeurl="https://launchpad.net/bugs/51835" 
    14 f= urllib.urlopen(zeurl) 
    15 zebug = bug(42) 
     50 
     51 
    1652# ici on a le corps principal 
    1753# faudrait faire un extract pour soulager la mémoire 
    18 soup = BeautifulSoup(f).body.contents[5].div.div 
    19 title = soup.h1.contents[0] 
    20 tbody = soup.findAll('tbody')[0].findAll('td') 
    21 product = tbody[0].a.contents[0] 
    22 status = tbody[1].contents[0] 
    23 importance = tbody[2].contents[0] 
     54#soup = BeautifulSoup(f).body.contents[5].div.div 
     55#title = soup.h1.contents[0] 
     56#tbody = soup.findAll('tbody')[0].findAll('td') 
     57#product = tbody[0].a.contents[0] 
     58#status = tbody[1].contents[0] 
     59#importance = tbody[2].contents[0] 
    2460#assigned = tbody[3].a.contents[2] 
    25 print title 
    26 print product 
    27 print status 
    28 print importance 
     61#print title 
     62#print product 
     63#print status 
     64#print importance 
    2965#need to prettify assigned 
    3066#print assigned 
    31 array_com = soup.findAll('div', recursive=0)[1].findAll('div','boardComment') 
    32 print array_com 
    33 j = 0 
    34 com_counter = 0 
    35 for i in array_com : 
    36         details = i.contents[1].findAll('a') 
    37         title = details[0].strong.contents[0] 
    38         poster = details[1].contents[0] 
    39         body = i.contents[3].findAll('p') 
    40         com_counter += 1 
    41         content="" 
    42         for z in body : 
    43                 phrase = z.contents[0].string 
    44                 new_phrase = phrase.strip().replace(" "," ") 
    45                 content = "%s\n%s" %(content,new_phrase) 
    46         newcom = comment(com_counter,content,poster,title,"date not implemented") 
    47         zebug.addComment(newcom) 
    48         j += 1 
    49 print zebug.comNbr() 
     67#array_com = soup.findAll('div', recursive=0)[1].findAll('div','boardComment') 
     68#print array_com 
     69#j = 0 
     70#com_counter = 0 
     71#for i in array_com : 
     72#       details = i.contents[1].findAll('a') 
     73#       title = details[0].strong.contents[0] 
     74#       poster = details[1].contents[0] 
     75#       body = i.contents[3].findAll('p') 
     76#       com_counter += 1 
     77#       content="" 
     78#       for z in body : 
     79#               phrase = z.contents[0].string 
     80#               new_phrase = phrase.strip().replace(" "," ") 
     81#               content = "%s\n%s" %(content,new_phrase) 
     82#       newcom = comment(com_counter,content,poster,title,"date not implemented") 
     83#       zebug.addComment(newcom) 
     84#       j += 1 
     85#print zebug.comNbr() 
    5086