Skip to content

Commit 6a67417

Browse files
committed
fixing strftime issue
1 parent 24a914a commit 6a67417

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

dist/ffiec-data-connect-0.2.0.tar.gz

-13.4 KB
Binary file not shown.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setup(
88
name='ffiec-data-connect',
99
python_requires='>3.9.0',
10-
version='0.2.6',
10+
version='0.2.7',
1111
license='MIT',
1212
description="Wrapper for the FFIEC's Webservice API",
1313
readme='README.md',

src/ffiec_data_connect.egg-info/PKG-INFO

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ffiec-data-connect
3-
Version: 0.2.0
3+
Version: 0.2.7
44
Summary: Wrapper for the FFIEC's Webservice API
55
Home-page: https://github.com/call-report/ffiec-data-connect
66
Author: Michael Handelman
@@ -11,6 +11,7 @@ Project-URL: Repo, https://github.com/call-report/ffiec-data-connect
1111
Project-URL: Additional Info, http://call.report
1212
Project-URL: Author, https://mikeh.dev
1313
Keywords: ffiec call report bank regulatory
14+
Requires-Python: >3.9.0
1415
Description-Content-Type: text/markdown
1516
License-File: LICENSE.txt
1617

@@ -42,12 +43,16 @@ Data returned from the Webservice may be returned as a native Python data struct
4243

4344
## Quickstart
4445

45-
__To run this Quick Start, you must have an account on the FFIEC Webservice at https://cdr.ffiec.gov/public/PWS/CreateAccount.aspx?PWS=true__
46+
1. To run this Quick Start, you must have an account on the FFIEC Webservice at https://cdr.ffiec.gov/public/PWS/CreateAccount.aspx?PWS=true
47+
2. After you create an account, verify your password, and complete the sign-in process, log into the public web interface here: https://cdr.ffiec.gov/Public/PWS/Login.aspx
48+
3. When you login, go to the "Account Details" tab. On this screen, look for the _Security Token_. This token is the password that you will use for the login credentials for ffiec-data-connect, __not the password__.
49+
50+
Sample code to login and collect reporting periods:
4651

4752
```
4853
from ffiec_data_connect import methods, credentials, ffiec_connection
4954

50-
creds = credentials.WebserviceCredentials(username="user1234", password="password1234")
55+
creds = credentials.WebserviceCredentials(username="USER_NAME_GOES_HERE", password="SECURITY_TOKEN_GOES_HERE")
5156

5257
conn = ffiec_connection.FFIECConnection()
5358

src/ffiec_data_connect/methods.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
validRegexList = [quarterStringRegex, yyyymmddRegex, yyyymmddDashRegex, mmddyyyyRegex]
2525

2626

27+
def _create_ffiec_date_from_datetime(indate: datetime) -> str:
28+
"""Converts a datetime object to a FFIEC-formatted date
29+
30+
Args:
31+
indate (datetime): the date to convert
32+
33+
Returns:
34+
str: the date in FFIEC format
35+
"""
36+
month_str = str(indate.month)
37+
day_str = str(indate.day)
38+
year_str = str(indate.year)
39+
40+
mmddyyyy = month_str + "/" + day_str + "/" + year_str
41+
42+
return mmddyyyy
43+
2744
def _convert_any_date_to_ffiec_format(indate: str or datetime) -> str:
2845
"""Converts a string-based date or python datetime object to a FFIEC-formatted date
2946
@@ -35,15 +52,15 @@ def _convert_any_date_to_ffiec_format(indate: str or datetime) -> str:
3552
"""
3653

3754
if isinstance(indate, datetime):
38-
return indate.strftime("%-m/%-d/%Y")
55+
return _create_ffiec_date_from_datetime(indate)
3956
elif isinstance(indate, str):
4057
# does the date have two slashes?
4158
if indate.count("-") == 2:
42-
return datetime.strptime(indate, "%Y-%m-%d").strftime("%-m/%-d/%Y")
59+
return _create_ffiec_date_from_datetime(datetime.strptime(indate, "%Y-%m-%d"))
4360
elif indate.count("/") == 2:
44-
return datetime.strptime(indate, "%m/%d/%Y").strftime("%-m/%-d/%Y")
61+
return _create_ffiec_date_from_datetime(datetime.strptime(indate, "%m/%d/%Y"))
4562
elif len(indate) == 8:
46-
return datetime.strptime(indate, "%Y%m%d").strftime("%-m/%-d/%Y")
63+
return _create_ffiec_date_from_datetime(datetime.strptime(indate, "%Y%m%d"))
4764
else:
4865
# raise an error if we don't have a valid date
4966
raise(ValueError("Invalid date format. Must be a string in the format of 'YYYY-MM-DD', 'YYYYMMDD', 'MM/DD/YYYY', or a python datetime object"))
@@ -118,10 +135,10 @@ def _is_valid_date_or_quarter(reporting_period: str or datetime) -> bool:
118135

119136
def _return_ffiec_reporting_date(indate: datetime or str) -> str:
120137
if isinstance(indate, datetime):
121-
return indate.strftime("%-m/%-d/%Y")
138+
return _create_ffiec_date_from_datetime(indate)
122139
elif isinstance(indate, str):
123140
if indate[1] == "Q":
124-
return _convert_quarter_to_date(indate).strftime("%-m/%-d/%Y")
141+
return _create_ffiec_date_from_datetime(_convert_quarter_to_date(indate))
125142
else:
126143
ffiec_date = _convert_any_date_to_ffiec_format(indate)
127144
ffiec_date_month = ffiec_date.split("/")[0]

src/ffiec_data_connect/xbrl_processor.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ def _process_xml(data: bytes, output_date_format: str):
5858

5959
return ret_data
6060

61+
62+
def _create_ffiec_date_from_datetime(indate: datetime) -> str:
63+
"""Converts a datetime object to a FFIEC-formatted date
64+
65+
Args:
66+
indate (datetime): the date to convert
67+
68+
Returns:
69+
str: the date in FFIEC format
70+
"""
71+
month_str = str(indate.month)
72+
day_str = str(indate.day)
73+
year_str = str(indate.year)
74+
75+
mmddyyyy = month_str + "/" + day_str + "/" + year_str
76+
77+
return mmddyyyy
78+
6179
def _process_xbrl_item(name, items, date_format):
6280
# incoming is a data dictionary
6381
results = []
@@ -75,7 +93,7 @@ def _process_xbrl_item(name, items, date_format):
7593

7694
# transform the date to the requested date format
7795
if date_format == 'string_original':
78-
quarter = datetime.strptime(quarter, '%Y-%m-%d').strftime('%-m/%-d/%Y')
96+
quarter = _create_ffiec_date_from_datetime(datetime.strptime(quarter, '%Y-%m-%d'))
7997
elif date_format == 'string_yyyymmdd':
8098
quarter = datetime.strptime(quarter, '%Y-%m-%d').strftime('%Y%m%d')
8199
elif date_format == 'python_format':

0 commit comments

Comments
 (0)