當前位置: 首頁>>代碼示例>>Python>>正文


Python Transaction.card_serial方法代碼示例

本文整理匯總了Python中models.Transaction.card_serial方法的典型用法代碼示例。如果您正苦於以下問題:Python Transaction.card_serial方法的具體用法?Python Transaction.card_serial怎麽用?Python Transaction.card_serial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Transaction的用法示例。


在下文中一共展示了Transaction.card_serial方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: scrapeCard

# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import card_serial [as 別名]
def scrapeCard(br, session, cardID, cardSerial):
    #follows link to View Card Summary page for a particular card
    response1 = br.follow_link(url_regex=r"CardSummary.aspx\?card_id=" + cardID).read()
    #follows link to View Usage History page for a particular card
    response1 = br.follow_link(text_regex=r"View Usage History").read()
    br.select_form(name="aspnetForm")
    response1 = br.submit().read()
    br.select_form(name="aspnetForm")
    
    #transaction status either 'All' or 'Successful' or 'Failed Autoloads';
    #'All' includes every succesful transaction including failed (card didn't swipe or error)  
    br["ctl00$MainContent$ddlTransactionStatus"] = ["All"]

    br.submit()
    
    #wmata only started posting data in 2010, pulls all available months
    for year in xrange(2010, 2011+1):
        for month in xrange(1, 12+1):
            time_period = ("%d%02d" % (year, month))
            print "\t", time_period

            #opens link to 'print' version of usage page for easier extraction 
            br.open("https://smartrip.wmata.com/Card/CardUsageReport2.aspx?card_id=" +
                    cardID + "&period=M&month=" + time_period)
            response1 = br.follow_link(text_regex=r"Print Version").read()
           
            #extracts data from html table, writes to csv
            soup = BeautifulSoup.BeautifulSoup(response1)
            table = soup.find('table', {'class': 'reportTable'})
            if table is None:
                continue
            rows = table.findAll('tr')
            it = iter(rows)    
            try:
                while True:
                    cols = it.next().findAll('td')
                    if len(cols) == 0:
                        continue #ignore blank rows
                    rowspan = int(cols[0].get('rowspan', '1'))

                    parsedCols = [td.find(text=True) for td in cols]
                    (sequence, timestamp, description, operator, entry, exit) = parsedCols[0:6]

                    purses = []
                    purses.append(parsedCols[6:9])

                    if rowspan > 1:
                        for i in xrange(1, rowspan):
                            cols = it.next().findAll('td')
                            purses.append([td.find(text=True) for td in cols])

                    txn = Transaction(sequence, timestamp, description, operator, entry, exit, purses)
                    txn.card_id = cardID
                    txn.card_serial = cardSerial
                    session.add(txn)
            except StopIteration:
                pass

            session.commit()
開發者ID:kurtraschke,項目名稱:WMATA-SmarTrip-Scraper,代碼行數:61,代碼來源:scraper.py


注:本文中的models.Transaction.card_serial方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。