Merge lp:~chsn/parcel-tracker/tnt into lp:parcel-tracker

Proposed by Erik Christiansson
Status: Merged
Approved by: Vsevolod Velichko
Approved revision: 174
Merged at revision: 176
Proposed branch: lp:~chsn/parcel-tracker/tnt
Merge into: lp:parcel-tracker
Diff against target: 47 lines (+43/-0)
1 file modified
parcel_tracker_lib/postservices/tnt.py (+43/-0)
To merge this branch: bzr merge lp:~chsn/parcel-tracker/tnt
Reviewer Review Type Date Requested Status
Vsevolod Velichko Pending
Review via email: mp+172391@code.launchpad.net

Commit message

TNT service by Erik Christiansson.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'parcel_tracker_lib/postservices/tnt.py'
2--- parcel_tracker_lib/postservices/tnt.py 1970-01-01 00:00:00 +0000
3+++ parcel_tracker_lib/postservices/tnt.py 2013-07-01 18:40:32 +0000
4@@ -0,0 +1,43 @@
5+#!/usr/bin/env python
6+# -*- coding: utf-8 -*-
7+
8+### BEGIN LICENSE
9+# Copyright © 2012-2013 Vsevolod Velichko <torkvema@gmail.com>
10+# Copyright © 2012 Carlos da Costa <c.costa@outlook.com>
11+# Copyright © 2012-2013 Erik Christiansson <erik@christiansson.net>
12+# Copyright © 2013 Pål Sollie <sollie@sparkz.no>
13+# This program is free software: you can redistribute it and/or modify it
14+# under the terms of the GNU General Public License version 3, as published
15+# by the Free Software Foundation.
16+#
17+# This program is distributed in the hope that it will be useful, but
18+# WITHOUT ANY WARRANTY; without even the implied warranties of
19+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
20+# PURPOSE. See the GNU General Public License for more details.
21+#
22+# You should have received a copy of the GNU General Public License along
23+# with this program. If not, see <http://www.gnu.org/licenses/>.
24+### END LICENSE
25+
26+from . import TrackingService
27+
28+import re
29+from dateutil.parser import parse as parsedate
30+
31+class TntService(TrackingService):
32+ """TNT service"""
33+
34+ name = 'TNT'
35+ url = 'http://www.tnt.com/webtracker/tracking.do'
36+ post = 'cons=%(number)s'
37+
38+ def _parse_page(self, html):
39+ html = html.decode('utf-8')
40+ res = re.search(r'<table[^>]*class="appTable">.*?<table[^>]*class="appTable">.*?</tr>(.*?)</tbody>', html, re.DOTALL)
41+ if res is None:
42+ return []
43+ return [
44+ (oper.strip(), parsedate('%s %s' % (date.strip(), time.strip())), loc.strip())
45+ for date, time, loc, oper
46+ in re.findall(r'<tr.*?<td[^>]*>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>', res.group(1), re.DOTALL)
47+ ]

Subscribers

People subscribed via source and target branches