diff --git a/docs/appendix/01_use_cases.md b/docs/appendix/01_use_cases.md index c117f5b..ff0f0ac 100644 --- a/docs/appendix/01_use_cases.md +++ b/docs/appendix/01_use_cases.md @@ -13,4 +13,6 @@ | 文章标题 | 简要介绍 | |---|---| -| [Python With 关键字和语句](https://www.ossez.com/t/python-with/13387) | 针对 with 关键字的使用进行了一些解答。 | +| [Python With 关键字和语句](https://www.ossez.com/t/python-with/13387) | 针对 with 关键字的使用进行了一些解答 | +| [Python DataTime 日期处理](https://www.ossez.com/t/python-datatime/13388) | 关于日期函数处理的一些小的介绍和讨论 | +| [Python 日期格式和时间以及当前时间和时间戳](https://www.ossez.com/t/python/13389) | 关于时间和当前时间的时间戳的获取 | diff --git a/requirements.txt b/requirements.txt index df5ae38..53a6226 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ yfinance==0.1.54 + +python-dateutil~=2.8.1 +setuptools~=54.0.0 \ No newline at end of file diff --git a/tests/DateTime.py b/tests/DateTime.py new file mode 100644 index 0000000..0622a15 --- /dev/null +++ b/tests/DateTime.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Python script to Process DateTime +# Author - HoneyMoose + +import datetime + +json_filename = 'resources/black_rock_test.json' + +today = datetime.date.today() +print("Today's date:", today) + +# 从字符串创建日期对象 +date_user = datetime.datetime.strptime('1/1/2021', '%m/%d/%Y') +print("格式化后的日期对象:", date_user) + +# 日期对象通过对格式化输出 +print("日期对象格式化输出 1 =", today.strftime("%d/%m/%Y")) +print("日期对象格式化输出 2 =", today.strftime("%B %d, %Y")) +print("日期对象格式化输出 3 =", today.strftime("%m/%d/%y")) +print("日期对象格式化输出 4 =", today.strftime("%b-%d-%Y")) + +# 当前时间戳 +now = datetime.datetime.now() +print("当前时间戳:", now) diff --git a/tests/FileWith.py b/tests/FileWith.py index 221189c..93e7efb 100644 --- a/tests/FileWith.py +++ b/tests/FileWith.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Python script to Read file from JSON and convert to YAML # Author - HoneyMoose (https://www.ossez.com) diff --git a/tests/Json2Yaml.py b/tests/Json2Yaml.py index b13090a..0862022 100644 --- a/tests/Json2Yaml.py +++ b/tests/Json2Yaml.py @@ -1,22 +1,36 @@ # 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 ruamel.yaml as yaml +from dateutil.relativedelta import relativedelta json_filename = 'resources/black_rock_test.json' 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 with open(json_filename) as json_file: data = json.load(json_file) - print(type(data)) + data_bod = data['date_of_birth'] - for data_dict in data: - label_id = data_dict['label_id'] - print(str(label_id)) -json_file.close() + if get_age(data_bod) >= 65: + data[ELIGIBLE_FOR_RETIREMENT] = True + else: + data[ELIGIBLE_FOR_RETIREMENT] = False # Write to YAML with open(yaml_filename, 'w') as yaml_file: diff --git a/tests/resources/black_rock_test.json b/tests/resources/black_rock_test.json index b608e34..e26a7fc 100644 --- a/tests/resources/black_rock_test.json +++ b/tests/resources/black_rock_test.json @@ -1,10 +1,5 @@ -[ - { - "label_id": 603, - "user_name": "YUCHENG-L1" - }, - { - "label_id": 604, - "user_name": "YUCHENG-L2" - } -] \ No newline at end of file +{ + "first_name": "John", + "last_name": "Doe", + "date_of_birth": "1/1/2021" +} \ No newline at end of file diff --git a/tests/resources/honeymoose_test.json b/tests/resources/honeymoose_test.json index b608e34..e26a7fc 100644 --- a/tests/resources/honeymoose_test.json +++ b/tests/resources/honeymoose_test.json @@ -1,10 +1,5 @@ -[ - { - "label_id": 603, - "user_name": "YUCHENG-L1" - }, - { - "label_id": 604, - "user_name": "YUCHENG-L2" - } -] \ No newline at end of file +{ + "first_name": "John", + "last_name": "Doe", + "date_of_birth": "1/1/2021" +} \ No newline at end of file