forked from haochi/personalcapital
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.py
45 lines (35 loc) · 1.14 KB
/
entry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import json
import numpy as np
import pandas as pd
from os import path
import matplotlib.pyplot as plt
from argparse import (
ArgumentParser,
ArgumentDefaultsHelpFormatter
)
from collections import defaultdict, Counter
from requests import Session
from personalcapital.analyze import get_report
from personalcapital.etl import update_transactions
def report():
if "PEW_PAYLOAD_URL" not in os.environ:
raise EnvironmentError("PEW_PAYLOAD_URL is not set.")
report = get_report()
session = Session()
response = session.post(os.environ["PEW_PAYLOAD_URL"], json=report)
print(json.dumps(report, indent=4))
def get_clargs():
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument(dest="action", choices=['report', 'update'], help="Action to perform.")
return parser.parse_args()
def main():
def _main(action):
if action == 'update':
update_transactions()
elif action == 'report':
report()
else:
raise ValueError("Unsupported action '{}'".format(action))
args = get_clargs()
_main(args.action)