File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import getpass
3
+ import base64
4
+ import time
5
+
6
+
7
+ CONFIG_FILE_PATH = "config.py"
8
+
9
+ CONFIG_FILE_TEMPLATE = """credentials = dict(api_key='{0}') """
10
+
11
+
12
+ # get hashed credentials
13
+ try :
14
+ api_key = base64 .b64encode (raw_input ("enter/paste API Key: " ).encode ()).decode ()
15
+ except :
16
+ api_key = base64 .b64encode (input ("enter/paste API Key: " ).encode ()).decode ()
17
+ print (" Hashed: {}\n " .format (api_key ))
18
+
19
+ new_config = CONFIG_FILE_TEMPLATE .format (api_key )
20
+
21
+ # check if config file exists
22
+ if not os .path .isfile (CONFIG_FILE_PATH ):
23
+ # create new config file
24
+ with open (CONFIG_FILE_PATH , "w" ) as config_file :
25
+ config_file .write (new_config )
26
+ print ("{} created successfully" .format (CONFIG_FILE_PATH ))
27
+ else :
28
+ with open (CONFIG_FILE_PATH , "r" ) as config_file :
29
+ cur_config = config_file .read ()
30
+ if new_config != cur_config :
31
+ # update config file
32
+ with open (CONFIG_FILE_PATH , "w" ) as config_file :
33
+ config_file .writelines (new_config )
34
+ print ("{} updated successfully" .format (CONFIG_FILE_PATH ))
35
+ else :
36
+ print ("{} already contains latest credentials" .format (CONFIG_FILE_PATH ))
37
+ time .sleep (2 )
38
+
You can’t perform that action at this time.
0 commit comments