Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using YYYY-MM-DD for dates in the sales report #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Sample config:
"key_file": "./AuthKey_AAAAAAAAA.p8",
"issuer_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"vendor": "3333333",
"start_date": "2019-02-01T00:00:00Z"
"start_date": "2019-02-01T00:00:00Z",
"convert_dates": false
}
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

setup(name='tap-appstore',
version='0.2.1-airbyte',
version='0.2.1.1',
description='Singer.io tap for extracting data from the App Store Connect API',
author='JustEdro',
url='https://github.com/JustEdro',
Expand Down
21 changes: 19 additions & 2 deletions tap_appstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
BOOKMARK_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
TIME_EXTRACTED_FORMAT = '%Y-%m-%dT%H:%M:%S%z'

DATE_COLUMNS = {
"end_date", "begin_date", "event_date",
"original_start_date", "purchase_date"
}

API_REQUEST_FIELDS = {
'subscription_event_report': {
'reportType': 'SUBSCRIPTION_EVENT',
Expand Down Expand Up @@ -147,7 +152,16 @@ def tsv_to_list(tsv):
line_cols = line.split('\t')
for i, column in enumerate(header):
if i < len(line_cols):
line_obj[column] = line_cols[i].strip()
value = line_cols[i].strip()
if Context.config['convert_dates']:
if column in DATE_COLUMNS:
if value.count("/") == 2:
try:
dt = datetime.strptime(value, "%m/%d/%Y")
value = dt.strftime("%Y-%m-%d")
except ValueError:
pass
line_obj[column] = value
data.append(line_obj)

return data
Expand Down Expand Up @@ -270,12 +284,15 @@ def main():
Context.config['issuer_id']
)

if "convert_dates" not in Context.config:
Context.config['convert_dates'] = False


# If discover flag was passed, run discovery mode and dump output to stdout
if args.discover:
catalog = discover(api)
Context.config = args.config
print(json.dumps(catalog, indent=2))

else:
Context.tap_start = utils.now()
if args.catalog:
Expand Down