forked from huaisha1224/jd-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcel.py
More file actions
39 lines (34 loc) · 1.38 KB
/
excel.py
File metadata and controls
39 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from pandas import DataFrame
import pandas as pd
from time import strftime
import os
def save_to_csv(dealtime,number,vercode, amount):
"""
写入内容到csv
"""
file_path = strftime("jd-assistant_%Y_%m.csv") # 按照当前系统时间创建文件
dealtime = dealtime.split(' ')[0] # 切割时间取年月日
number = number + '\t'
vercode = vercode + '\t'
#判断文件是否存在
if os.path.exists(file_path):
data = pd.DataFrame({'下单时间':dealtime, '订单号':number, '验证码':vercode, '实付金额':amount}, index=[0])
# data['订单号'] = data['订单号'].apply(str) + '\t'
# data['验证码'] = data['验证码'].apply(str) + '\t'
data.to_csv(file_path, index=None, mode='a', header=None)
#print('追加')
else:
data = pd.DataFrame({'下单时间':dealtime, '订单号':number, '验证码':vercode, '实付金额':amount}, index=[0])
# data['订单号'] = data['订单号'].apply(str) + '\t'
# data['验证码'] = data['验证码'].apply(str) + '\t'
data.to_csv(file_path, index=None)
#print('新增')
if __name__ == '__main__':
# time = '2021-09-07'
time = '2021-09-07 08:22:05'
number = '221697592258'
vercode = '7102298241802'
amount = '248.00'
save_to_csv(time, number, vercode, amount)