日期参数化
This commit is contained in:
+10
-12
@@ -5,6 +5,7 @@ from goojia_utils import MAIN_MONGO_CLIENT, dateutils, ElasticSearchClient
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
|
||||
es45_client = ElasticSearchClient(host='192.168.0.45')
|
||||
@@ -14,20 +15,18 @@ district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_
|
||||
city_df = pd.read_excel('/opt/airflow/dags/repo/dags/mt/supply/data/美团19城市列表.xlsx')
|
||||
cities = city_df['城市列表'].values.tolist()
|
||||
|
||||
# 1. 获取「今天」
|
||||
today = datetime.date.today()
|
||||
# 2. 获取当前月的第一天
|
||||
first = today.replace(day=1)
|
||||
# 3. 减一天,得到上个月的最后一天
|
||||
last_month = first - datetime.timedelta(days=1)
|
||||
path = "/home/airflow/data/mt"
|
||||
|
||||
month_start = last_month.strftime("%Y%m") + '01'
|
||||
curr_month_start = dateutils.format_date(datetime.datetime.now(), '%Y%m') + '01'
|
||||
logging.info(month_start + ' ' + curr_month_start)
|
||||
output_date = sys.argv[1] if sys.argv[1] else dateutils.format_date(datetime.datetime.now(), '%Y%m')
|
||||
|
||||
seaweed_new_result_df = pd.read_csv(path + '/FJW_COMM_' + output_date + '.csv', sep='@', encoding='utf-8')
|
||||
|
||||
month_start = dateutils.format_date(dateutils.add_months(dateutils.parse_date(output_date, '%Y%m'), months=-1), '%Y%m') + '01'
|
||||
curr_month_start = output_date + '01'
|
||||
logging.info("日期信息:" + month_start + ' ' + curr_month_start)
|
||||
|
||||
month_start_date = dateutils.parse_date(month_start, '%Y%m%d')
|
||||
curr_month_start_date = dateutils.parse_date(curr_month_start, '%Y%m%d')
|
||||
path = "/home/airflow/data/mt"
|
||||
|
||||
result_df = pd.read_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@', encoding='utf-8')
|
||||
|
||||
@@ -97,5 +96,4 @@ columns = ['id', 'city', 'region', 'name', 'alias', 'address', 'addr_alias', 'av
|
||||
'build_structure', 'finish_building_date',
|
||||
'developer', 'house_type', 'house_area', 'deal_num', 'district_facilitys', 'school', 'market', 'subway',
|
||||
'bank', 'hospital', 'status']
|
||||
result_df.to_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@',
|
||||
encoding='utf-8', index=False, columns=columns)
|
||||
result_df.to_csv(path + '/FJW_COMM_' + output_date + '.csv', sep='@', encoding='utf-8', index=False, columns=columns)
|
||||
Reference in New Issue
Block a user