本文整理汇总了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()