Merge lp:~josejuan05/parcel-tracker/quickly_branch into lp:parcel-tracker

Proposed by josejuan05
Status: Merged
Merged at revision: 444
Proposed branch: lp:~josejuan05/parcel-tracker/quickly_branch
Merge into: lp:parcel-tracker
Diff against target: 26 lines (+4/-4)
1 file modified
parcel_tracker_lib/postservices/uspscom.py (+4/-4)
To merge this branch: bzr merge lp:~josejuan05/parcel-tracker/quickly_branch
Reviewer Review Type Date Requested Status
Vsevolod Velichko Approve
Review via email: mp+321941@code.launchpad.net

Description of the change

Updated the USPS postservice

To post a comment you must log in.
444. By josejuan05

Updated USPS postservice added whitespace stripping

Revision history for this message
Vsevolod Velichko (torkvemada) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'parcel_tracker_lib/postservices/uspscom.py'
2--- parcel_tracker_lib/postservices/uspscom.py 2016-09-16 11:08:21 +0000
3+++ parcel_tracker_lib/postservices/uspscom.py 2017-04-05 05:49:05 +0000
4@@ -34,18 +34,18 @@
5
6 def _parse_page(self, html):
7 html = html.decode('utf-8', 'ignore')
8- res = re.search(r'<table[^>]*id="tc-hits".*?<tbody[^>]*>(.*?)</tbody>', html, re.DOTALL | re.UNICODE)
9+ res = re.search(r'<table[^>]*class="tracking_history".*?<tbody[^>]*>(.*?)</tbody>', html, re.DOTALL | re.UNICODE)
10 if res is None:
11 return []
12 html = res.group(1)
13 result = []
14- for res in re.findall(r'<td class="date-time">\s*<p>(.*?)</p>\s*</td>\s*<td class="status">\s*(<!--.*?-->)?\s*<p[^>]*>\s*(<span[^>]*>)?(.*?)<.*?\s*(</p)?\s*</td>\s*<td class="location">\s*<p>(.*?)</td>', html, re.DOTALL | re.UNICODE):
15+ for res in re.findall(r'<tr[^>]*?>\s*<td>\s*(.*?)\s*</td>\s*<td>\s*(.*?)\s*?</td>\s*<td>\s*(.*?)\s*</td>\s*</tr>', html, re.DOTALL | re.UNICODE):
16 opdate, operation, location = (
17 re.sub('\s+',
18 ' ',
19- unescape(untagify(x.strip())).replace('\n', ' '),
20+ unescape(untagify(x.strip())).replace('\n', ' ').strip(),
21 flags=re.UNICODE)
22- for x in (res[0], res[3], res[5])
23+ for x in (res[0], res[1], res[2])
24 )
25 opdate = parsedate(opdate)
26 result.append((operation, opdate, location))

Subscribers

People subscribed via source and target branches