~torkvemada/parcel-tracker/quickly_trunk

« back to all changes in this revision

Viewing changes to parcel_tracker_lib/post_services.py

  • Committer: Vsevolod Velichko
  • Date: 2012-08-25 20:36:13 UTC
  • mfrom: (81.1.4 parcel-tracker)
  • Revision ID: torkvema@gmail.com-20120825203613-xf26cr17cvffjxi0
Merge of Carlos da Costa fix for Correios.com service.

Show diffs side-by-side

added added

removed removed

Lines of Context:
516
516
 
517
517
    url = 'http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=%(number)s'
518
518
    def _parse_page(self, html):
519
 
        html = html.decode('utf-8', 'ignore')
520
 
        res = re.findall(r'<td rowspan=1>(.*?)</td><td>(.*?)</td><td><FONT COLOR=".*?">(.*?)</font></td>',
521
 
                         html, re.DOTALL|re.IGNORECASE)
522
 
        return [ (op, parsedate(date, dayfirst=True), ' '.join(post.split())) for (date, post, op) in res]
 
519
        html = html.decode('ISO-8859-1', 'ignore')
 
520
        res = re.findall(r'<tr><td rowspan=.*?>(.*?)</td><td>(.*?)</td><td><FONT COLOR=".*?">(.*?)</font></td></tr>(?:\s*?<tr><td colspan=2>(.*?)</td></tr>)?',
 
521
                         html, re.DOTALL|re.IGNORECASE|re.UNICODE)
 
522
        result = []
 
523
        for (date, post, op, obs) in res:
 
524
            resdate = parsedate(date, dayfirst=True)
 
525
            respost = u' '.join(post.split())
 
526
            if obs:
 
527
                resop = u' '.join(op.split() + [u'-'] + obs.split())
 
528
            else:
 
529
                resop = u' '.join(op.split())
 
530
            result.append((resop, resdate, respost))
 
531
        return result
523
532
 
524
533
if __name__ == '__main__':
525
534
    logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
537
546
    #service = UkrposhtaComService('RB041697087UA')
538
547
    #service = DhlDeService('129921786448')
539
548
    #service = UpsComService('1Z882E910397601345')
540
 
    service = CorreiosComService('RQ867951061BR')
 
549
    service = CorreiosComService('RD024810847SE')
541
550
    for i in service.fetch():
542
551
        print u'\t'.join([unicode(j) for j in i])