3
3
4
4
import click
5
5
from getpass import getpass
6
+ import uuid
6
7
import sys
7
8
8
9
from revolut import Revolut , __version__ , get_token_step1 , get_token_step2 , signin_biometric , extract_token
9
10
10
11
# Usage : revolut_cli.py --help
11
12
12
- _CLI_DEVICE_ID = 'revolut_cli'
13
-
14
-
15
13
@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
+ )
16
20
@click .option (
17
21
'--token' , '-t' ,
18
22
envvar = "REVOLUT_TOKEN" ,
34
38
version = __version__ ,
35
39
message = '%(prog)s, based on [revolut] package version %(version)s'
36
40
)
37
- def main (token , language , account ):
41
+ def main (device_id , token , language , account ):
38
42
""" Get the account balances on Revolut """
39
43
40
44
if token is None :
41
45
print ("You don't seem to have a Revolut token" )
42
46
answer = input ("Would you like to generate a token [yes/no]? " )
43
47
selection (answer )
48
+ device_id = 'cli_{}' .format (uuid .getnode ()) # Unique id for a machine
44
49
while token is None :
45
50
try :
46
- token = get_token ()
51
+ token = get_token (device_id = device_id )
47
52
except Exception as e :
48
53
login_error_handler (e )
49
54
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 )
51
58
account_balances = rev .get_account_balances ()
52
59
if account :
53
60
print (account_balances .get_account_by_name (account ).balance )
54
61
else :
55
62
print (account_balances .csv (lang = language ))
56
63
57
64
58
- def get_token ():
65
+ def get_token (device_id ):
59
66
phone = input (
60
67
"What is your mobile phone (used with your Revolut "
61
68
"account) [ex : +33612345678] ? " )
62
69
password = getpass (
63
70
"What is your Revolut app password [ex: 1234] ? " )
64
71
verification_channel = get_token_step1 (
65
- device_id = _CLI_DEVICE_ID ,
72
+ device_id = device_id ,
66
73
phone = phone ,
67
74
password = password
68
75
)
@@ -79,7 +86,7 @@ def get_token():
79
86
)
80
87
81
88
response = get_token_step2 (
82
- device_id = _CLI_DEVICE_ID ,
89
+ device_id = device_id ,
83
90
phone = phone ,
84
91
code = code ,
85
92
)
@@ -91,18 +98,21 @@ def get_token():
91
98
selfie_filepath = input (
92
99
"Provide a selfie image file path (800x600) [ex : selfie.png] " )
93
100
response = signin_biometric (
94
- _CLI_DEVICE_ID , phone , access_token , selfie_filepath )
101
+ device_id , phone , access_token , selfie_filepath )
95
102
96
103
token = extract_token (response )
97
104
token_str = "Your token is {}" .format (token )
105
+ device_id_str = "Your device id is {}" .format (device_id )
98
106
99
107
dashes = len (token_str ) * "-"
100
- print ("\n " .join (("" , dashes , token_str , dashes , "" )))
108
+ print ("\n " .join (("" , dashes , token_str , device_id_str , dashes , "" )))
101
109
print ("You may use it with the --token of this command or set the "
102
110
"environment variable in your ~/.bash_profile or ~/.bash_rc, "
103
111
"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 ))
105
113
print ("or" )
114
+ print ('echo "export REVOLUT_DEVICE_ID={}" >> ~/.bash_profile'
115
+ .format (device_id ))
106
116
print ('echo "export REVOLUT_TOKEN={}" >> ~/.bash_profile'
107
117
.format (token ))
108
118
return token
0 commit comments