task-brand-daily.py
1.55 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import pymysql
import json
import datetime
# 根据id给出所有尺码
conn = pymysql.connect(host="192.168.103.250", user='root',
passwd='123456', charset="utf8")
def readBrandFromMysql():
sql_query = "SELECT PRODUCT_ID as productId, BRAND_ID FROM du_info.BRAND_PRODUCT WHERE 1"
df = pd.read_sql(sql_query, con=conn)
return df
def readBrandNameFromMysql():
sql_query = "SELECT ID as BRAND_ID, NAME FROM du_info.BRAND_7 WHERE 1"
df = pd.read_sql(sql_query, con=conn)
return df
def brandAmount(file, outPath):
df = pd.read_excel(file, 'Sheet1')
brand_df = pd.concat([readBrandFromMysql()], sort=True)
name_df = pd.concat([readBrandNameFromMysql()], sort=True)
result = pd.merge(df, brand_df, on=['productId'])
amount = result['amount'].groupby([result['BRAND_ID']]).sum()
amount.rename(columns={'BRAND_NAME': 'name'}, inplace=True)
priceData = pd.DataFrame(amount, columns=['amount'])
finalData = priceData.reset_index()
finalData2 = pd.merge(finalData, name_df, on=['BRAND_ID'])
finalData1 = finalData2.sort_values(
by='amount', ascending=False)
nowTime = datetime.datetime.now()
yesTime = nowTime + datetime.timedelta(days=-1)
filePath = outPath+'/brand-daily-'+yesTime.strftime('%m%d')+'.xlsx'
finalData1.to_excel(filePath, sheet_name='Sheet1', index=0)
print(json.dumps({
'path': filePath
}))
if(sys.argv.__len__() > 2):
brandAmount(sys.argv[2], sys.argv[1])