colisprive: fixes

fixed history parsing
rewrite for browser2

Signed-off-by: Matthieu Weber <mweber+weboob@free.fr>
Signed-off-by: Romain Bignon <romain@symlink.me>
This commit is contained in:
Matthieu Weber 2015-05-22 20:23:12 +03:00 committed by Romain Bignon
commit ce8c66a7d1
3 changed files with 21 additions and 32 deletions

View file

@ -17,25 +17,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.deprecated.browser import Browser
from weboob.browser import PagesBrowser, URL
from .pages import TrackPage, ErrorPage
__all__ = ['ColispriveBrowser']
class ColispriveBrowser(PagesBrowser):
class ColispriveBrowser(Browser):
PROTOCOL = 'https'
DOMAIN = 'www.colisprive.com'
ENCODING = 'utf8'
PAGES = {'https://www.colisprive.com/moncolis/pages/detailColis.aspx.*': TrackPage,
'https://www.colisprive.com/moncolis/Default.aspx.*': ErrorPage,
}
track_page = URL('https://www.colisprive.com/moncolis/pages/detailColis.aspx\?numColis=(?P<id>.+)', TrackPage)
error_page = URL('https://www.colisprive.fr', ErrorPage)
def get_tracking_info(self, _id):
self.location('https://www.colisprive.com/moncolis/pages/detailColis.aspx?numColis=%s' % _id)
if not self.is_on_page(TrackPage):
return None
return self.page.get_info(_id)
return self.track_page.go(id=_id).get_info(_id)

View file

@ -17,8 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.parcel import CapParcel
from weboob.tools.backend import Module
from weboob.capabilities.parcel import CapParcel
from .browser import ColispriveBrowser
@ -36,5 +36,4 @@ class ColispriveModule(Module, CapParcel):
BROWSER = ColispriveBrowser
def get_parcel_tracking(self, _id):
with self.browser:
return self.browser.get_tracking_info(_id)
return self.browser.get_tracking_info(_id)

View file

@ -18,8 +18,8 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from datetime import date
from weboob.deprecated.browser import Page
from weboob.capabilities.parcel import Parcel, Event
from weboob.browser.pages import HTMLPage
from weboob.capabilities.parcel import Parcel, Event, ParcelNotFound
def update_status(p, status):
@ -27,28 +27,28 @@ def update_status(p, status):
p.status = status
class TrackPage(Page):
class TrackPage(HTMLPage):
def get_info(self, _id):
p = Parcel(_id)
statustr = self.document.xpath('//tr[@class="bandeauText"]')[0]
status = self.parser.tocleanstring(statustr.xpath('td')[1])
statustr = self.doc.xpath('//tr[@class="bandeauText"]')[0]
status = statustr.xpath('td')[1].text
p.info = status
p.status = p.STATUS_UNKNOWN
p.history = []
for i, tr in enumerate(self.document.xpath('//div[@class="mainbloc4Evt"]//tr')):
for i, tr in enumerate(self.doc.xpath('//table[@class="tableHistoriqueColis"]//tr[@class="bandeauText"]')):
tds = tr.findall('td')
try:
if tds[0].attrib['class'] != "titrestatutdate2":
if tds[0].attrib['class'] != "tdText":
continue
except:
continue
ev = Event(i)
ev.location = None
ev.activity = self.parser.tocleanstring(tds[1])
ev.activity = tds[1].text
if u"Votre colis a été expédié par votre webmarchand" in ev.activity:
update_status(p, p.STATUS_PLANNED)
elif u"Votre colis est pris en charge par Colis Privé" in ev.activity:
@ -59,12 +59,12 @@ class TrackPage(Page):
update_status(p, p.STATUS_IN_TRANSIT)
elif u"Votre colis a été livré" in ev.activity:
update_status(p, p.STATUS_ARRIVED)
ev.date = date(*reversed([int(x) for x in self.parser.tocleanstring(tds[0]).split('/')]))
ev.date = date(*reversed([int(x) for x in tds[0].text.split('/')]))
p.history.append(ev)
try:
datelivre = self.document.xpath('//div[@class="NoInstNoRecla"]')
clean = self.parser.tocleanstring(datelivre[0])
datelivre = self.doc.xpath('//div[@class="NoInstNoRecla"]')
clean = datelivre[0].text
if "Votre colis a déja été livré" in clean:
p.status = p.STATUS_ARRIVED
except:
@ -72,5 +72,6 @@ class TrackPage(Page):
return p
class ErrorPage(Page):
pass
class ErrorPage(HTMLPage):
def get_info(self, _id):
raise ParcelNotFound("No such ID: %s" % _id)