本文整理汇总了Python中tablib.Dataset.headers方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.headers方法的具体用法?Python Dataset.headers怎么用?Python Dataset.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tablib.Dataset
的用法示例。
在下文中一共展示了Dataset.headers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _import
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def _import(self):
"""Execute the import."""
import_dataset = Dataset()
fieldtypes = self._prepare_dataset_to_import()
import_dataset.headers = self.read_dataset.headers
inProj = Proj(init='epsg:25831')
outProj = Proj(init='epsg:4326')
for row in self.read_dataset.dict:
# Ignore rows with emtpy lat or lon
if row['lon'] is not None and row['lat'] is not None:
row['lon'], row['lat'] = transform(
inProj,
outProj,
row['lon'],
row['lat']
)
row = self._check_fieldtypes(row, fieldtypes)
new = []
for key in row:
new.append(row[key])
import_dataset.append(new)
db = connection.cursor()
import_dataset.headers = None
with tempfile.NamedTemporaryFile() as f:
f.write(import_dataset.csv)
f.seek(0)
try:
db.copy_from(f, 'storm_drain',
columns=(self.read_dataset.headers),
sep=",",
null='null')
self._add_version(
self.request,
self.read_dataset.dict[0]['version']
)
self.response = {
'success': True,
'headers': self.read_dataset.headers
}
except Exception as e:
error = str(e).replace('\n', ' ').replace('\r', '')
self.response = {'success': False, 'err': error}
示例2: exportDivSchedulesRefFormat
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def exportDivSchedulesRefFormat(self, startgameday, prefix=""):
headers = ['Game#', 'Game#', 'Tourn Match#','Date', 'Day', 'Time', 'Division', 'Round', 'Home', 'Visitor', 'Field', 'cr_trust', 'ar_trust', 'm_trust']
datasheet = Dataset(title=prefix)
datasheet.headers = list(headers)
schedule_list = self.dbinterface.findDivisionSchedulePHMSARefFormat(startgameday)
tabformat_list = [(_offset+x[match_id_CONST], x[match_id_CONST], tournMapGamedayIdToCalendar(x[gameday_id_CONST]), tournMapGamedayIdToDate(x[gameday_id_CONST]),
datetime.strptime(x[start_time_CONST],"%H:%M").strftime("%I:%M %p"),
x[age_CONST]+x[gen_CONST], x[round_CONST],
x[home_CONST], x[away_CONST],
self.fieldinfo[self.findexerGet(x[venue_CONST])]['name'],
_reftrust_level[_rindexerGet(getTournDivID(x[age_CONST], x[gen_CONST]))]['cr'],
_reftrust_level[_rindexerGet(getTournDivID(x[age_CONST], x[gen_CONST]))]['ar'],
_reftrust_level[_rindexerGet(getTournDivID(x[age_CONST], x[gen_CONST]))]['ment'])
for x in schedule_list] if prefix else [(mapGamedayIdToCalendar(x[gameday_id_CONST],format=1), 'Saturday',
datetime.strptime(x[start_time_CONST],"%H:%M").strftime("%I:%M %p"),
x[age_CONST]+x[gen_CONST],
x[home_CONST], x[away_CONST],
self.fieldinfo[self.findexerGet(x[venue_CONST])]['name'])
for x in schedule_list]
if prefix:
atabformat_list = [(_offset+i, j[0], j[1], j[2], j[3], j[4], j[5], j[6], j[7], j[8], j[9], j[10], j[11], j[12]) for i,j in enumerate(tabformat_list)]
else:
atabformat_list = tabformat_list
for tabformat in atabformat_list:
datasheet.append(tabformat)
sheet_xls_relpath = prefix+'_RefFormat.xls'
sheet_xls_abspath = os.path.join('/home/henry/workspace/datagraph/bottle_baseball/download/xls',
sheet_xls_relpath)
with open(sheet_xls_abspath,'wb') as f:
f.write(datasheet.xls)
f.close()
示例3: generate_fieldxls
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def generate_fieldxls(self):
headers = ['Game Date', 'Day', 'Time', 'Division', 'Home',
'Visitor', 'Venue']
datasheet_list = list()
for fieldinfo in self.fieldinfo_list:
field_name = fieldinfo['field_name']
field_id = fieldinfo['field_id']
datasheet = Dataset(title=field_name)
datasheet.headers = list(headers)
match_list = self.sdbinterface.get_schedule('field_id',
field_id=field_id)
tabformat_list = [(x['game_date'],
parser.parse(x['game_date']).strftime("%a"),
datetime.strptime(x['start_time'], "%H:%M").strftime("%I:%M%p"),
x['div_age']+x['div_gen'], x['home'], x['away'], field_name)
for x in match_list]
for tabformat in tabformat_list:
datasheet.append(tabformat)
datasheet_list.append(datasheet)
book = Databook(datasheet_list)
bookname_xls_relpath = self.schedcol_name + "_byField.xls"
bookname_xls_fullpath = os.path.join(self.dir_path, bookname_xls_relpath)
with open(bookname_xls_fullpath,'wb') as f:
f.write(book.xls)
f.close()
return [{'path':bookname_xls_relpath}]
示例4: exportDivTeamSchedules
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def exportDivTeamSchedules(self, div_id, age, gen, numteams, prefix=""):
headers = ['Gameday#', 'Game Date', 'Day', 'Start Time', 'Venue', 'Home Team', 'Away Team']
datasheet_list = []
for team_id in range(1, numteams+1):
team_str = age+gen+str(team_id)
datasheet = Dataset(title=team_str)
datasheet.headers = list(headers)
teamdata_list = self.dbinterface.findTeamSchedule(age, gen, team_id)
tabformat_list = [(x[gameday_id_CONST], tournMapGamedayIdToCalendar(x[gameday_id_CONST]), tournMapGamedayIdToDate(x[gameday_id_CONST]),
datetime.strptime(x[start_time_CONST],"%H:%M").strftime("%I:%M %p"),
self.fieldinfo[self.findexerGet(x[venue_CONST])]['name'],
x[home_CONST], x[away_CONST]) for x in teamdata_list]
for tabformat in tabformat_list:
datasheet.append(tabformat)
datasheet_list.append(datasheet)
book = Databook(datasheet_list)
cdir = os.path.dirname(__file__)
bookname_xls = prefix+age + gen +'_schedule.xls'
bookname_html = prefix+age + gen +'_schedule.html'
booknamefull_xls = os.path.join('/home/henry/workspace/datagraph/bottle_baseball/download/xls', bookname_xls)
booknamefull_html = os.path.join('~/workspace/datagraph/bottle_baseball/download/html', bookname_html)
with open(booknamefull_xls,'wb') as f:
f.write(book.xls)
f.close()
'''
示例5: exportDivSchedules
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def exportDivSchedules(self, startgameday, prefix=""):
headers = ['Match ID', 'Gameday#', 'Game Date', 'Day', 'Time', 'Division', 'Home', 'Away', 'Field', '', 'Comment']
datasheet_list = []
for division in self.leaguedivinfo:
div_id = division['div_id']
div_age = division['div_age']
div_gen = division['div_gen']
div_str = div_age + div_gen
datasheet = Dataset(title=div_str)
datasheet.headers = list(headers)
divdata_list = self.dbinterface.findElimTournDivisionSchedule(div_age, div_gen, min_game_id=startgameday)
tabformat_list = [(y[match_id_CONST], x[gameday_id_CONST], tournMapGamedayIdToCalendar(x[gameday_id_CONST]), tournMapGamedayIdToDate(x[gameday_id_CONST]), datetime.strptime(x[start_time_CONST],"%H:%M").strftime("%I:%M %p"), div_str, y[home_CONST], y[away_CONST], self.fieldinfo[self.findexerGet(y[venue_CONST])]['name'], '', y[comment_CONST]) for x in divdata_list for y in x[gameday_data_CONST]]
for tabformat in tabformat_list:
datasheet.append(tabformat)
datasheet.append_separator("Prefix Legend: 'S'-Seeded Team#, 'W'-Winning Team (See Match ID), 'L'-Losing Team)")
datasheet_list.append(datasheet)
book = Databook(datasheet_list)
cdir = os.path.dirname(__file__)
bookname_xls = prefix+'.xls'
bookname_html = prefix+'.html'
booknamefull_xls = os.path.join('/home/henry/workspace/datagraph/bottle_baseball/download/xls', bookname_xls)
booknamefull_html = os.path.join('~/workspace/datagraph/bottle_baseball/download/html', bookname_html)
with open(booknamefull_xls,'wb') as f:
f.write(book.xls)
f.close()
示例6: render_to_response
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def render_to_response(self, context, **response_kwargs):
"""If exporting, generate a csv."""
if 'export' in self.request.GET:
data = Dataset()
data.headers = (
u'Name', u'Email', u'Phone', u'Zip', u'State', u'Joined',
u'Last login', u'Total Groups Joined',
u'Flags received', u'Messages sent', u'Staff?', u'Superuser?',
u'Banned?', u'Visits'
)
for user in self.get_queryset():
data.append((
user, user.email, user.phone, user.zip_code, user.state,
user.date_joined, user.last_login,
user.total_groups_joined,
user.flags_received, user.messages_sent,
user.is_staff, user.is_superuser, user.is_banned,
user.visit_count
))
response = HttpResponse(
data.csv,
content_type='text/csv'
)
response['Content-Disposition'] = 'attachment; filename=users.csv'
return response
else:
return super(UserReportListView, self).render_to_response(
context, **response_kwargs)
示例7: dump_program_reports
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def dump_program_reports():
print('Running program report dump...')
dataset = Dataset()
dataset.headers = ['Site ID', 'Mobile', 'Timestamp', 'Group', 'Program', 'Period code', 'Period number', 'Atot', 'Arel', 'Tin', 'Tout', 'Dead', 'DefT', 'Dcur', 'Dmed']
for report in ProgramReport.objects.select_related('group', 'program').order_by('created'):
if not report.reporter.mobile.startswith('+'):
continue
dataset.append([
report.site.hcid,
report.reporter.mobile,
timegm(report.created.utctimetuple()),
report.group.code,
report.program.code,
report.period_code,
report.period_number,
report.new_marasmic_patients,
report.readmitted_patients,
report.patients_transferred_in,
report.patients_transferred_out,
report.patient_deaths,
report.unconfirmed_patient_defaults,
report.patients_cured,
report.unresponsive_patients
])
with open('program_reports.csv', 'w') as f:
f.write(dataset.csv)
print('Done')
示例8: csv_output_computers
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def csv_output_computers():
"""Utility function to generate a CSV output of computers information from
Incredibus data, for audit/cleansing purposes.
"""
computers = Computer.objects.all()
d = Dataset()
d.headers = [
'ID',
'HOSTNAME',
'CHASSIS',
'PROBABLE OWNER EMAIL',
'PROBABLE OWNER CC',
'MANAGED BY EMAIL',
'ASSET NO.',
'SERIAL NO.'
]
for i in computers:
row = [i.pk, i.sam_account_name[:-1], i.chassis]
if i.probable_owner:
row += [i.probable_owner.email.lower(), i.probable_owner.cost_centre]
else:
row += ['', '']
if i.managed_by:
row += [i.managed_by.email.lower()]
else:
row += ['']
row += ['', i.serial_number]
d.append(row)
f = open('/tmp/computers.csv', 'w')
f.write(d.csv)
f.close()
示例9: generate_elimdivxls
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def generate_elimdivxls(self, genxls_id):
headers = ['Match ID', 'Game Date', 'Day', 'Time', 'Division', 'Home',
'Visitor', 'Venue', 'Round', 'Comment']
datasheet_list = list()
for divinfo in self.divinfo_list:
div_id = divinfo[genxls_id]
div_age = divinfo['div_age']
div_gen = divinfo['div_gen']
div_str = div_age + div_gen
datasheet = Dataset(title=div_str)
datasheet.headers = list(headers)
match_list = self.sdbinterface.get_schedule(genxls_id, div_age=div_age,
div_gen=div_gen, elim_flag=True)
# note conversions for time from 24-hour to am/pm format
tabformat_list = [(y['match_id'], x['game_date'],
parser.parse(x['game_date']).strftime("%a"),
datetime.strptime(x['start_time'], "%H:%M").strftime("%I:%M%p"),
div_str, self.team_map(div_id, y['home']), self.team_map(div_id, y['away']),
self.fieldinfo_list[self.findexerGet(y['venue'])]['field_name'],
y['around'], y['comment']) for x in match_list for y in x['gameday_data']]
for tabformat in tabformat_list:
datasheet.append(tabformat)
datasheet_list.append(datasheet)
book = Databook(datasheet_list)
bookname_xls_relpath = self.schedcol_name + "_byDivision.xls"
bookname_xls_fullpath = os.path.join(self.dir_path, bookname_xls_relpath)
with open(bookname_xls_fullpath,'wb') as f:
f.write(book.xls)
f.close()
return [{'path':bookname_xls_relpath}]
示例10: dataset
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def dataset(data, headers=None):
""" `data` is a list of dicts.
"""
dataset = Dataset()
dataset.dict = data
if headers:
dataset.headers = headers
return dataset
示例11: fetch_timetable
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [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
示例12: five_largest_graph_data_sheet
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def five_largest_graph_data_sheet(self):
work_sheet = Dataset(title="Five Largest Graph")
work_sheet.headers = ['iso', 'country', 'position', 'shown percentage', 'real percentage', 'donor']
for country in models.Recipient.objects.all():
table = FiveLargestGraph(country=country).as_list()
for position, disbursement in enumerate(table):
real = disbursement["percentage"]["real"]
formatted = disbursement["percentage"]["formatted"]
donor = disbursement["name"]
work_sheet.append([country.iso3, country.name, position + 1, formatted, real, donor])
return work_sheet
示例13: seven_largest_single_data_sheet
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def seven_largest_single_data_sheet(self):
work_sheet = Dataset(title="7 Largest Disbursements")
work_sheet.headers = ['iso', 'country', 'position', 'shown amount', 'shown donor']
for country in models.Recipient.objects.all():
table = LargestDisbursementTable(country=country).as_dictionary()["table"]
for position, disbursement in enumerate(table):
formatted = disbursement["disbursement"]
donor = disbursement["donor"]
work_sheet.append([country.iso3, country.name, position + 1, formatted, donor])
return work_sheet
示例14: other_disbursements_data_sheet
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def other_disbursements_data_sheet(self):
work_sheet = Dataset(title="Other disbursements")
work_sheet.headers = ['iso', 'country', 'amount of other disbursements vs 7 largest']
for country in models.Recipient.objects.all():
re_disb = re.compile("Other (\d+) Disb\s*")
disbursements = models.Disbursement.objects.filter(country=country)
other_disbursements = disbursements.get(donor__contains="Other ")
ndisb = int(re_disb.match(other_disbursements.donor).groups()[0])
total_disbursements_count = disbursements.count() - 1 + ndisb
work_sheet.append([country.iso3, country.name, total_disbursements_count])
return work_sheet
示例15: multilateral_and_foundation_table_data_sheet
# 需要导入模块: from tablib import Dataset [as 别名]
# 或者: from tablib.Dataset import headers [as 别名]
def multilateral_and_foundation_table_data_sheet(self):
work_sheet = Dataset(title="Multilateral-Foundation")
work_sheet.headers = ['iso', 'country', 'number of disbursements', 'total shown disbursement', 'total real disbursement']
for country in models.Recipient.objects.all():
table = MultilateralAndFoundationDisbursementSourcesTable(country=country).as_dictionary()
if len(table):
number = table["total"]["number_of_disbursements"]
amount_formatted = table["total"]["amount"]["formatted"]
amount_real = table["total"]["amount"].get("real", '')
work_sheet.append([country.iso3, country.name, number, amount_formatted, amount_real])
return work_sheet