forked from tducret/revolut-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revolut_transactions.py
73 lines (65 loc) · 1.97 KB
/
revolut_transactions.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import click
import json
import os
import sys
from datetime import datetime
from datetime import timedelta
from revolut import Revolut, __version__
@click.command()
@click.option(
'--device-id', '-d',
envvar="REVOLUT_DEVICE_ID",
type=str,
help='your Revolut token (or set the env var REVOLUT_DEVICE_ID)',
default='revolut_cli',
)
@click.option(
'--token', '-t',
envvar="REVOLUT_TOKEN",
type=str,
help='your Revolut token (or set the env var REVOLUT_TOKEN)',
)
@click.option(
'--language', '-l',
type=click.Choice(['en', 'fr']),
help='language for the csv header and separator',
default='fr'
)
@click.option(
'--from_date', '-t',
type=click.DateTime(formats=["%Y-%m-%d"]),
help='transactions lookback date in YYYY-MM-DD format (ex: "2019-10-26"). Default 30 days back',
default=(datetime.now()-timedelta(days=30)).strftime("%Y-%m-%d")
)
@click.option(
'--output_format', '-fmt',
type=click.Choice(['csv', 'json']),
help="output format",
default='csv',
)
@click.option(
'--reverse', '-r',
is_flag=True,
help='reverse the order of the transactions displayed',
)
def main(device_id, token, language, from_date, output_format, reverse):
""" Get the account balances on Revolut """
if token is None:
print("You don't seem to have a Revolut token. Use 'revolut_cli' to obtain one")
exit(1)
rev = Revolut(device_id=device_id, token=token)
account_transactions = rev.get_account_transactions(from_date)
if output_format == 'csv':
print(account_transactions.csv(lang=language, reverse=reverse))
elif output_format == 'json':
transactions = account_transactions.raw_list
if reverse:
transactions = reversed(transactions)
print(json.dumps(transactions))
else:
print("output format {!r} not implemented".format(output_format))
exit(1)
if __name__ == "__main__":
main()