Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit 6c413f4

Browse files
committed
Create a unique device_id (to fix issue #21)
1 parent d9dc032 commit 6c413f4

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

revolut_cli.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33

44
import click
55
from getpass import getpass
6+
import uuid
67
import sys
78

89
from revolut import Revolut, __version__, get_token_step1, get_token_step2, signin_biometric, extract_token
910

1011
# Usage : revolut_cli.py --help
1112

12-
_CLI_DEVICE_ID = 'revolut_cli'
13-
14-
1513
@click.command()
14+
@click.option(
15+
'--device-id', '-d',
16+
envvar="REVOLUT_DEVICE_ID",
17+
type=str,
18+
help='your Revolut token (or set the env var REVOLUT_DEVICE_ID)',
19+
)
1620
@click.option(
1721
'--token', '-t',
1822
envvar="REVOLUT_TOKEN",
@@ -34,35 +38,38 @@
3438
version=__version__,
3539
message='%(prog)s, based on [revolut] package version %(version)s'
3640
)
37-
def main(token, language, account):
41+
def main(device_id, token, language, account):
3842
""" Get the account balances on Revolut """
3943

4044
if token is None:
4145
print("You don't seem to have a Revolut token")
4246
answer = input("Would you like to generate a token [yes/no]? ")
4347
selection(answer)
48+
device_id = 'cli_{}'.format(uuid.getnode()) # Unique id for a machine
4449
while token is None:
4550
try:
46-
token = get_token()
51+
token = get_token(device_id=device_id)
4752
except Exception as e:
4853
login_error_handler(e)
4954

50-
rev = Revolut(device_id=_CLI_DEVICE_ID, token=token)
55+
if device_id is None:
56+
device_id = 'revolut_cli' # For retro-compatibility
57+
rev = Revolut(device_id=device_id, token=token)
5158
account_balances = rev.get_account_balances()
5259
if account:
5360
print(account_balances.get_account_by_name(account).balance)
5461
else:
5562
print(account_balances.csv(lang=language))
5663

5764

58-
def get_token():
65+
def get_token(device_id):
5966
phone = input(
6067
"What is your mobile phone (used with your Revolut "
6168
"account) [ex : +33612345678] ? ")
6269
password = getpass(
6370
"What is your Revolut app password [ex: 1234] ? ")
6471
verification_channel = get_token_step1(
65-
device_id=_CLI_DEVICE_ID,
72+
device_id=device_id,
6673
phone=phone,
6774
password=password
6875
)
@@ -79,7 +86,7 @@ def get_token():
7986
)
8087

8188
response = get_token_step2(
82-
device_id=_CLI_DEVICE_ID,
89+
device_id=device_id,
8390
phone=phone,
8491
code=code,
8592
)
@@ -91,18 +98,21 @@ def get_token():
9198
selfie_filepath = input(
9299
"Provide a selfie image file path (800x600) [ex : selfie.png] ")
93100
response = signin_biometric(
94-
_CLI_DEVICE_ID, phone, access_token, selfie_filepath)
101+
device_id, phone, access_token, selfie_filepath)
95102

96103
token = extract_token(response)
97104
token_str = "Your token is {}".format(token)
105+
device_id_str = "Your device id is {}".format(device_id)
98106

99107
dashes = len(token_str) * "-"
100-
print("\n".join(("", dashes, token_str, dashes, "")))
108+
print("\n".join(("", dashes, token_str, device_id_str, dashes, "")))
101109
print("You may use it with the --token of this command or set the "
102110
"environment variable in your ~/.bash_profile or ~/.bash_rc, "
103111
"for example :", end="\n\n")
104-
print(">>> revolut_cli.py --token={}".format(token))
112+
print(">>> revolut_cli.py --device-id={} --token={}".format(device_id, token))
105113
print("or")
114+
print('echo "export REVOLUT_DEVICE_ID={}" >> ~/.bash_profile'
115+
.format(device_id))
106116
print('echo "export REVOLUT_TOKEN={}" >> ~/.bash_profile'
107117
.format(token))
108118
return token

revolut_transactions.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33

44
import click
55
import json
6+
import os
67

78
from datetime import datetime
89
from datetime import timedelta
910

1011
from revolut import Revolut, __version__
1112

1213

13-
_CLI_DEVICE_ID = 'revolut_cli'
14-
15-
1614
@click.command()
15+
@click.option(
16+
'--device-id', '-d',
17+
envvar="REVOLUT_DEVICE_ID",
18+
type=str,
19+
help='your Revolut token (or set the env var REVOLUT_DEVICE_ID)',
20+
default='revolut_cli',
21+
)
1722
@click.option(
1823
'--token', '-t',
1924
envvar="REVOLUT_TOKEN",
@@ -43,13 +48,13 @@
4348
is_flag=True,
4449
help='reverse the order of the transactions displayed',
4550
)
46-
def main(token, language, from_date, output_format, reverse):
51+
def main(device_id, token, language, from_date, output_format, reverse):
4752
""" Get the account balances on Revolut """
4853
if token is None:
4954
print("You don't seem to have a Revolut token. Use 'revolut_cli' to obtain one")
5055
exit(1)
5156

52-
rev = Revolut(device_id=_CLI_DEVICE_ID, token=token)
57+
rev = Revolut(device_id=device_id, token=token)
5358
account_transactions = rev.get_account_transactions(from_date)
5459
if output_format == 'csv':
5560
print(account_transactions.csv(lang=language, reverse=reverse))

revolutbot.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# Usage : revolutbot.py --help
99

10-
_CLI_DEVICE_ID = 'revolut_cli'
1110
_BOT_PERCENT_MARGIN = 1 # at least 1% benefit to exchange
1211
_VERBOSE_MODE = False # can be changed with --verbose parameter
1312

@@ -17,6 +16,13 @@
1716

1817

1918
@click.command()
19+
@click.option(
20+
'--device-id', '-d',
21+
envvar="REVOLUT_DEVICE_ID",
22+
type=str,
23+
help='your Revolut token (or set the env var REVOLUT_DEVICE_ID)',
24+
default='revolut_cli',
25+
)
2026
@click.option(
2127
'--token', '-t',
2228
envvar="REVOLUT_TOKEN",
@@ -48,15 +54,15 @@
4854
version=__version__,
4955
message='%(prog)s, based on [revolut] package version %(version)s'
5056
)
51-
def main(token, simulate, historyfile, verbose, forceexchange):
57+
def main(device_id, token, simulate, historyfile, verbose, forceexchange):
5258
if token is None:
5359
print("You don't seem to have a Revolut token")
5460
print("Please execute revolut_cli.py first to get one")
5561
sys.exit(_RETURN_CODE_ERROR)
5662

5763
global _VERBOSE_MODE
5864
_VERBOSE_MODE = verbose
59-
rev = Revolut(device_id=_CLI_DEVICE_ID, token=token)
65+
rev = Revolut(device_id=device_id, token=token)
6066

6167
to_buy_or_not_to_buy(revolut=rev,
6268
simulate=simulate,

0 commit comments

Comments
 (0)