本文整理汇总了Python中tablib.Dataset.rpush方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.rpush方法的具体用法?Python Dataset.rpush怎么用?Python Dataset.rpush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tablib.Dataset
的用法示例。
在下文中一共展示了Dataset.rpush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_timetable
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import rpush [as 别名]
def fetch_timetable(browser, link):
# Utility method to return a nice Dataset from a timetable url
if debug:
puts('Fetching timetable from %s' % link)
response = browser.follow_link(link)
soup = BeautifulSoup(response.read())
table = soup.find('table')
timetable = []
for row in table.findAll('tr'):
title = None
title_test = row.find('td')
if title_test.find('span'):
title = title_test.getText()
values = []
for col in row.findAll('td')[1:]:
value = col.getText()
if value == ' ':
value = None
if isinstance(value, basestring) and ':' in value:
try:
time = value.strip().split(':')
time = datetime.time(*[int(s) for s in time])
except:
pass
else:
value = time
values.append(value)
timetable.append((title, values))
while len(timetable):
if 'TRAIN NO.' not in timetable[0][0]:
del timetable[0]
else:
break
train_nums = timetable[0]
data = Dataset()
data.headers = train_nums[1]
if debug:
puts(repr(data.headers))
for place, times in timetable[1:]:
if debug:
puts(repr((place, times)))
data.rpush(times, tags=[place.title().replace('`S', "'s")])
#Strip out TRAIN NO. columns
while 1:
try:
del data['TRAIN NO.']
except:
break
return data