更新代码

This commit is contained in:
YuCheng Hu 2021-03-12 10:21:18 -05:00
parent ff361819f9
commit ac0a2ce5d6
No known key found for this signature in database
GPG Key ID: 1E5CBEF8B550FB7D
4 changed files with 33 additions and 26 deletions

View File

@ -1 +1,4 @@
yfinance==0.1.54 yfinance==0.1.54
python-dateutil~=2.8.1
setuptools~=54.0.0

View File

@ -1,22 +1,36 @@
# Python script to Read file from JSON and convert to YAML # Python script to Read file from JSON and convert to YAML
# Author - HoneyMoose (https://www.ossez.com) # Author - yucheng.hu@insight.com
import datetime
import json import json
import ruamel.yaml as yaml import ruamel.yaml as yaml
from dateutil.relativedelta import relativedelta
json_filename = 'resources/black_rock_test.json' json_filename = 'resources/black_rock_test.json'
yaml_filename = 'resources/black_rock_test.yaml' yaml_filename = 'resources/black_rock_test.yaml'
ELIGIBLE_FOR_RETIREMENT = 'eligible_for_retirement'
# Get Difference Years
def get_age(data_input):
date_user = datetime.datetime.strptime(data_input, '%m/%d/%Y')
date_current = datetime.datetime.now()
time_difference = relativedelta(date_current, date_user)
return time_difference.years
# Read and process JSON # Read and process JSON
with open(json_filename) as json_file: with open(json_filename) as json_file:
data = json.load(json_file) data = json.load(json_file)
print(type(data)) data_bod = data['date_of_birth']
for data_dict in data: if get_age(data_bod) >= 65:
label_id = data_dict['label_id'] data[ELIGIBLE_FOR_RETIREMENT] = True
print(str(label_id)) else:
json_file.close() data[ELIGIBLE_FOR_RETIREMENT] = False
# Write to YAML # Write to YAML
with open(yaml_filename, 'w') as yaml_file: with open(yaml_filename, 'w') as yaml_file:

View File

@ -1,10 +1,5 @@
[ {
{ "first_name": "John",
"label_id": 603, "last_name": "Doe",
"user_name": "YUCHENG-L1" "date_of_birth": "1/1/2021"
}, }
{
"label_id": 604,
"user_name": "YUCHENG-L2"
}
]

View File

@ -1,10 +1,5 @@
[ {
{ "first_name": "John",
"label_id": 603, "last_name": "Doe",
"user_name": "YUCHENG-L1" "date_of_birth": "1/1/2021"
}, }
{
"label_id": 604,
"user_name": "YUCHENG-L2"
}
]