root/launchpad_test.py

Revision 78, 3.9 kB (checked in by ploum, 20 months ago)

trying to make conseil working with the new launchpad. The new launchpad is pretty from outside but the HTML code produced is pure crap !

Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3import gtk
4import gobject
5import gtk.glade
6import urllib, urllib2, mechanize, cookielib
7import ClientForm
8from bug import *
9from BeautifulSoup import BeautifulSoup
10# You have to change this if you have another storage
11#from auth_dummy import user
12
13zeurl="https://launchpad.net/bugs/51835"
14#zeurl="https://staging.launchpad.net/products/launchpad/+bug/51835"
15#zeurl="https://staging.launchpad.net/products/launchpad/+bug/51835/+addcomment"
16base_url = "https://staging.launchpad.net/"
17
18#cookies = cookielib.CookieJar()
19#req = urllib2.Request("https://staging.launchpad.net/")
20#resp = urllib2.urlopen(req)
21#cookies.extract_cookies(resp, req)
22
23def login(username, password):
24        data = {'form': 'login',
25                'loginpage_email': username,
26                'loginpage_password': password,
27                'loginpage_submit_login': 'Log In'}
28        url = base_url + 'products/+login'
29        fetch(url, data)
30
31def fetch(url, data):
32        postdata = urllib.urlencode(data)
33        req = urllib2.Request(url, postdata)
34        #req = urllib2.Request(url)
35        c = cookies._cookies_for_request(req)[0]
36        req.add_header('Cookie', '%s=%s' % (c.name, c.value))
37        #print c.value
38        return urllib2.urlopen(req)
39
40#editurl="to_get"
41#login("","")
42#request= mecha.Request(zeurl)
43#data={ 'field.status' : 'Rejected',
44#               'FORM_SUBMIT' : 'Save Changes'}
45#data={}
46#f= fetch(zeurl, data)
47#print f.read()
48#response = urllib2.urlopen(zeurl)
49#forms = ClientForm.ParseResponse(f, backwards_compat=False)
50#print "$$$$$$$$$$"
51#print forms
52#print "$$$$$$$$$$"
53#print "*****MODIFY THE BUG****"
54#modify=forms[1]
55#print "*****ADD A COMMENT****"
56#comment=forms[1]
57
58#print modify
59print "****"
60#print comment
61#comment.set_value("Tentative de commentaire","field.comment")
62#modify.set_value(["Rejected"],name="field.status")
63#modify["field.status"]=["Rejected"]
64#request = modify.click()
65#request = comment.click()
66#print request
67#result = urllib2.urlopen(request)
68#print result.geturl()
69#print result.info()  # headers
70#print result.read()  # body
71
72#toprint = result.read()
73
74#print toprint
75
76
77#forms = ClientForm.ParseResponse(f, backwards_compat=False)
78#for i in forms :
79#       print i
80
81
82
83f= urllib.urlopen(zeurl)
84compt=0
85#soup1 = BeautifulSoup(f).body.contents[6]
86soup = BeautifulSoup(f).findAll(id="maincontent")[0]
87print "£££££££££££££"
88div_soup = soup.findAll('div')
89array_com = soup.findAll('div', recursive=0)[1].findAll('div','boardComment')
90j = 0
91com_counter = 0
92for i in array_com :
93        print i
94        print "**************"
95        details = i.findAll('a')
96        title = details[1].contents[0].strip()
97        print "title = %s " %title
98        poster = details[1].contents[0]
99        body = i.contents[3].findAll('p')
100        com_counter += 1
101        content=""
102        for z in body :
103                phrase = ''
104                for ligne in z.contents :
105                        if ligne.string != None :
106                                phrase += ligne.string.strip()
107                content += self.htmlify(phrase)
108                content += "\n\n"
109        newcom = comment(com_counter,content,poster,title,"00/00/00")
110                       
111# ici on a le corps principal
112# faudrait faire un extract pour soulager la mémoire
113#soup = BeautifulSoup(f).body.contents[5].div.div
114#title = soup.h1.contents[0]
115#tbody = soup.findAll('tbody')[0].findAll('td')
116#product = tbody[0].a.contents[0]
117#status = tbody[1].contents[0]
118#importance = tbody[2].contents[0]
119#assigned = tbody[3].a.contents[2]
120#print title
121#print product
122#print status
123#print importance
124#need to prettify assigned
125#print assigned
126#array_com = soup.findAll('div', recursive=0)[1].findAll('div','boardComment')
127#print array_com
128#j = 0
129#com_counter = 0
130#for i in array_com :
131#       details = i.contents[1].findAll('a')
132#       title = details[0].strong.contents[0]
133#       poster = details[1].contents[0]
134#       body = i.contents[3].findAll('p')
135#       com_counter += 1
136#       content=""
137#       for z in body :
138#               phrase = z.contents[0].string
139#               new_phrase = phrase.strip().replace(" "," ")
140#               content = "%s\n%s" %(content,new_phrase)
141#       newcom = comment(com_counter,content,poster,title,"date not implemented")
142#       zebug.addComment(newcom)
143#       j += 1
144#print zebug.comNbr()
145
Note: See TracBrowser for help on using the browser.