Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Args:
col (int): Column number
cell (xlrd.sheet.Cell): Excel cell
Returns:
str: Formatted value
"""
pat = self.get(col)
log('col=%r, pat=%r, cell=%r', col, pat, cell)
if not pat or cell.ctype in (TYPE_BOOLEAN, TYPE_ERROR, TYPE_EMPTY):
return self._format_default(cell)
if cell.ctype == TYPE_DATE:
dt = xldate_as_datetime(cell.value, self.datemode)
formatted = dt.strftime(pat)
else:
try:
formatted = pat % cell.value
except Exception: # Try new-style formatting
try:
formatted = pat.format(cell.value)
except Exception:
formatted = cell.value
# log('pat=%r, %r --> %r', pat, cell.value, formatted)
return formatted
'assets_type':data[0],
'name':data[1],
'sn':data[2],
'buy_user':int(data[5]),
'management_ip':data[6],
'manufacturer':data[7],
'model':data[8],
'provider':data[9],
'status':int(data[10]),
'put_zone':int(data[11]),
'group':int(data[12]),
'project':int(data[13]),
'business':int(data[14]),
}
if data[3]:assets['buy_time'] = xlrd.xldate.xldate_as_datetime(data[3],0)
if data[4]:assets['expire_date'] = xlrd.xldate.xldate_as_datetime(data[4],0)
if assets.get('assets_type') in ['vmser','server']:
server_assets = {
'ip':data[15],
'keyfile':data[16],
'username':data[17],
'passwd':data[18],
'hostname':data[19],
'port':data[20],
'raid':data[21],
'line':data[22],
}
else:
net_assets = {
'ip':data[15],
'bandwidth':data[16],
'port_number': data[17],
def format(self, v):
try:
return xldate_as_datetime(v, self.wb.datemode)
except:
return None
fields = sheet.row_values(0) if sheet.nrows else []
fields = [
str(value)
if not isinstance(value, basestring) and value is not None
else value or 'Unnamed: {0}'.format(index + 1)
for index, value in enumerate(fields)
]
data = []
for i in range(1, sheet.nrows):
row = []
for cell in sheet.row(i):
if cell.ctype == xlrd.XL_CELL_DATE:
value = xlrd.xldate.xldate_as_datetime(cell.value, wb.datemode).isoformat()
else:
value = cell.value
row.append(value)
data.append(dict(zip(fields, row)))
header = header_population(fields)
sheets[sheet.name] = (header, data)
return sheets
'assets_type':data[0],
'name':data[1],
'sn':data[2],
'buy_user':int(data[5]),
'management_ip':data[6],
'manufacturer':data[7],
'model':data[8],
'provider':data[9],
'status':int(data[10]),
'put_zone':int(data[11]),
'group':int(data[12]),
# 'project':int(data[13]),
# 'business':int(data[14]),
}
if data[3]:assets['buy_time'] = xlrd.xldate.xldate_as_datetime(data[3],0)
if data[4]:assets['expire_date'] = xlrd.xldate.xldate_as_datetime(data[4],0)
if assets.get('assets_type') in ['vmser','server']:
server_assets = {
'ip':data[13],
'keyfile':data[14],
'username':data[15],
'passwd':data[16],
'hostname':data[17],
'port':data[18],
'raid':data[19],
'line':data[20],
}
else:
net_assets = {
'ip':data[13],
'bandwidth':data[14],
'port_number': data[15],
def xldates(self):
"""
Return a numpy array containing the Excel numerical dates
corresponding to the dates of the dataset.
"""
if 'XLDATES' not in self._dataf.columns:
print('Converting datetimes to xldates...', end=' ')
timedeltas = (
self._dataf.index - xlrd.xldate.xldate_as_datetime(4000, 0))
self._dataf['XLDATES'] = (
timedeltas.total_seconds()/(3600 * 24) + 4000)
print('done')
return self._dataf['XLDATES'].values
def _parse_cell(cell_contents, cell_typ):
"""converts the contents of the cell into a pandas
appropriate object"""
if cell_typ == XL_CELL_DATE:
# Use the newer xlrd datetime handling.
try:
cell_contents = xldate.xldate_as_datetime(cell_contents, epoch1904)
except OverflowError:
return cell_contents
# Excel doesn't distinguish between dates and time,
# so we treat dates on the epoch as times only.
# Also, Excel supports 1900 and 1904 epochs.
year = (cell_contents.timetuple())[0:3]
if (not epoch1904 and year == (1899, 12, 31)) or (
epoch1904 and year == (1904, 1, 1)
):
cell_contents = time(
cell_contents.hour,
cell_contents.minute,
cell_contents.second,
cell_contents.microsecond,
)