~chsn/parcel-tracker/parcel-tracker-gls

« back to all changes in this revision

Viewing changes to parcel_tracker_lib/postservices/gls.py

  • Committer: Erik Christiansson
  • Date: 2013-06-18 17:06:45 UTC
  • Revision ID: erik@christiansson.net-20130618170645-9ytcucftplx2oppc
Added GLS Group service

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
### BEGIN LICENSE
 
5
# Copyright © 2012 Vsevolod Velichko <torkvema@gmail.com>
 
6
# Copyright © 2012 Carlos da Costa <c.costa@outlook.com>
 
7
# Copyright © 2013 Erik Christiansson <erik@christiansson.net>
 
8
# This program is free software: you can redistribute it and/or modify it 
 
9
# under the terms of the GNU General Public License version 3, as published 
 
10
# by the Free Software Foundation.
 
11
 
12
# This program is distributed in the hope that it will be useful, but 
 
13
# WITHOUT ANY WARRANTY; without even the implied warranties of 
 
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
15
# PURPOSE.  See the GNU General Public License for more details.
 
16
 
17
# You should have received a copy of the GNU General Public License along 
 
18
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
### END LICENSE
 
20
 
 
21
from . import TrackingService
 
22
 
 
23
import re
 
24
from dateutil.parser import parse as parsedate
 
25
 
 
26
class GlsService(TrackingService):
 
27
    """GLS Group service"""
 
28
 
 
29
    name = 'GLS Group'
 
30
    url = 'http://www.gls-group.eu/276-I-PORTAL-WEB/content/GLS/PL01/EN/5004.htm?txtRefNo=%(number)s&txtAction=71000'
 
31
 
 
32
    def _parse_page(self, html):
 
33
        html = html.decode('utf-8')
 
34
        res = re.search(r'<table class="resultlist">(.*?)</table>', html, re.DOTALL)
 
35
        if res is None:
 
36
            return []
 
37
        html = res.group(1)
 
38
        return [(loc, parsedate(date), oper) for date, loc, oper in re.findall(r'<tr class="details">\s*<td>\s*(.*?)\s*</td>\s*<td>\s*(.*?)\s*</td>.*?</td>\s*$
 
39