日期参数化
This commit is contained in:
@@ -6,6 +6,7 @@ from goojia_utils import MAIN_MONGO_CLIENT, dateutils, commutils
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
district_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'district_stat')
|
||||
sqmetre_rent_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'sqmetre_rent')
|
||||
@@ -16,15 +17,12 @@ cities = city_df['城市列表'].values.tolist()
|
||||
|
||||
path = "/home/airflow/data/mt"
|
||||
|
||||
# 1. 获取「今天」
|
||||
today = datetime.date.today()
|
||||
# 2. 获取当前月的第一天
|
||||
first = today.replace(day=1)
|
||||
# 3. 减一天,得到上个月的最后一天
|
||||
last_month = first - datetime.timedelta(days=1)
|
||||
output_date = sys.argv[1] if sys.argv[1] else dateutils.format_date(datetime.datetime.now(), '%Y%m')
|
||||
|
||||
month_start = last_month.strftime("%Y%m") + '01'
|
||||
curr_month_start = dateutils.format_date(datetime.datetime.now(), '%Y%m') + '01'
|
||||
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')
|
||||
@@ -75,8 +73,6 @@ rent_df = rent_df.rename(columns={'district_name': 'name', 'avg_price': 'rent_pr
|
||||
avg_df = avg_df[['city', 'region', 'name', 'avg_price']]
|
||||
rent_df = rent_df[['city', 'region', 'name', 'rent_price']]
|
||||
|
||||
|
||||
seaweed_new_result_df = pd.read_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@', encoding='utf-8')
|
||||
result_df = pd.merge(seaweed_new_result_df, avg_df, how='left', on=['city', 'region', 'name'])
|
||||
result_df = pd.merge(result_df, rent_df, how='left', on=['city', 'region', 'name'])
|
||||
|
||||
@@ -92,4 +88,4 @@ def format_rent(x):
|
||||
|
||||
|
||||
result_df = result_df.apply(lambda x: format_rent(x), axis=1)
|
||||
result_df.to_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv', sep='@', encoding='utf-8', index=False)
|
||||
result_df.to_csv(path + '/FJW_COMM_' + output_date + '.csv', sep='@', encoding='utf-8', index=False)
|
||||
|
||||
Reference in New Issue
Block a user