当前位置: 首页>>代码示例>>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;未经允许,请勿转载。