Commit a2dfc1e1 authored by litaolemo's avatar litaolemo

update

parent 3b8ad835
......@@ -168,6 +168,8 @@ def get_es_word(word,start_ts):
class WritrExcel():
def __init__(self):
self.workbook = xlwt.Workbook(encoding='utf-8')
def set_style(self, name, height, bold=False):
style = xlwt.XFStyle() # 初始化样式
......@@ -180,11 +182,10 @@ class WritrExcel():
return style
# 写入Excel
def write_excel(self, path, rows):
def write_excel(self, sheet_name, rows):
# 创建工作簿
workbook = xlwt.Workbook(encoding='utf-8')
# 创建sheet
data_sheet = workbook.add_sheet('Sheet1')
data_sheet = self.workbook.add_sheet(sheet_name)
# 将样式定义在循环之外
default = self.set_style('Times New Roman', 220, True)
j = k = 0
......@@ -199,8 +200,11 @@ class WritrExcel():
raise
# data_sheet.write(1, i, row1[i], self.set_style('Times New Roman', 220, True))
k = k + 1
workbook.save(path)
print("写入文件成功,共" + str(k) + "行数据")
print("写入sheet成功,共" + str(k) + "行数据")
def save_excel(self,path):
self.workbook.save(path)
def get_search_keywrod_dict():
......@@ -307,7 +311,7 @@ def get_how_word_crawler_count(data_index, start_ts, end_ts, week_num, last_week
craw_one_week_count = buck["doc_count"]
push_num = res_dict[platform][0]
oneline_num = res_dict[platform][1]
new_line = (week_num,platform,craw_one_week_count,push_num,oneline_num)
new_line = (week_num,platform,craw_one_week_count,push_num,oneline_num,"")
res_data.append(new_line)
return res_data
......@@ -350,10 +354,10 @@ if __name__ == "__main__":
print(craw_one_week)
# query 一周抓取详情
all_data_week = craw_query_one_week(data_index, start_ts, end_ts, week_num, last_week_num, year )
craw_one_week.append(())
craw_one_week.append(all_data_week)
path = "近1周数据统计结果.xls"
WritrExcel().write_excel(path, tuple(all_data_week))
exl = WritrExcel()
exl.write_excel("热点内容抓取周报", tuple(craw_one_week))
exl.write_excel("query抓取周报", tuple(all_data_week))
exl.save_excel(path)
print(u'创建demo.xls文件成功')
send_email_tome()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment