11import configparser
22import os
33import click
4+ import time
45from rich .console import Console
56from rich .panel import Panel
67from rich import box
@@ -21,36 +22,76 @@ def __init__(self):
2122 self .config .read (self .config_file )
2223 self .init ()
2324
24- def _write_config_file (self ):
25- with open (self .config_file , 'w' ) as f :
26- self .config .write (f )
25+ def init (self ):
26+ if self .config ['profile' ]['first_name' ] != '' :
27+ self .console .print (Panel ('[bold]Welcome Back, ' + self .config ['profile' ]['first_name' ] + '! :smiley:\n '
28+ '[dark_blue]Kroger[/dark_blue] CLI[/bold]' , box = box .ASCII ))
29+ else :
30+ self .console .print (Panel ('[bold]Welcome to [dark_blue]Kroger[/dark_blue] CLI[/bold] (unofficial command '
31+ 'line interface)' , box = box .ASCII ))
2732
28- def _init_config_file (self ):
29- self .config .add_section ('main' )
30- self .config ['main' ]['username' ] = ''
31- self .config ['main' ]['password' ] = ''
32- self .config .add_section ('profile' )
33- self .config ['profile' ]['first_name' ] = ''
34- self ._write_config_file ()
33+ self .prompt_store_selection ()
3534
36- def set_credentials (self , username , password ):
37- self .username = username
38- self .password = password
35+ if self .username is None and self .config ['main' ]['username' ] != '' :
36+ self .username = self .config ['main' ]['username' ]
37+ self .password = self .config ['main' ]['password' ]
38+ else :
39+ self .prompt_credentials ()
3940
40- def prompt_option (self ):
41+ self .prompt_options ()
42+
43+ def prompt_store_selection (self ):
44+ pass
45+ # TODO:
46+ # self.console.print('Please select preferred store')
47+
48+ def prompt_credentials (self ):
49+ self .console .print ('In order to continue, please enter your username (email) and password for kroger.com '
50+ '(also works with Ralphs, Dillons, Smith’s and other Kroger’s Chains)' )
51+ username = click .prompt ('Username (email)' )
52+ password = click .prompt ('Password' )
53+ self ._set_credentials (username , password )
54+
55+ def prompt_options (self ):
4156 while True :
4257 self .console .print ('[bold]1[/bold] - Display account info' )
4358 self .console .print ('[bold]2[/bold] - Clip all digital coupons' )
59+ self .console .print ('[bold]8[/bold] - Re-Enter username/password' )
4460 self .console .print ('[bold]9[/bold] - Exit' )
4561 option = click .prompt ('Please select from one of the options' , type = int )
4662
4763 if option == 1 :
4864 self ._option_account_info ()
4965 elif option == 2 :
5066 self ._option_clip_coupons ()
67+ elif option == 8 :
68+ self .prompt_credentials ()
5169 elif option == 9 :
5270 return
5371
72+ self .console .rule ()
73+ time .sleep (2 )
74+
75+ def _write_config_file (self ):
76+ with open (self .config_file , 'w' ) as f :
77+ self .config .write (f )
78+
79+ def _init_config_file (self ):
80+ self .config .add_section ('main' )
81+ self .config ['main' ]['username' ] = ''
82+ self .config ['main' ]['password' ] = ''
83+ self .config ['main' ]['domain' ] = 'kroger.com'
84+ self .config .add_section ('profile' )
85+ self .config ['profile' ]['first_name' ] = ''
86+ self ._write_config_file ()
87+
88+ def _set_credentials (self , username , password ):
89+ self .username = username
90+ self .password = password
91+ self .config ['main' ]['username' ] = self .username
92+ self .config ['main' ]['password' ] = self .password
93+ self ._write_config_file ()
94+
5495 def _option_account_info (self ):
5596 info = self .api .get_account_info ()
5697 if info is None :
@@ -67,25 +108,7 @@ def _option_account_info(self):
67108 self .config ['profile' ]['state' ] = info ['address' ]['stateCode' ]
68109 self .config ['profile' ]['zip' ] = info ['address' ]['zip' ]
69110 self ._write_config_file ()
70- self .console .log (self .config .items (section = 'profile' ))
111+ self .console .print (self .config .items (section = 'profile' ))
71112
72113 def _option_clip_coupons (self ):
73114 self .api .clip_coupons ()
74-
75- def _sign_in (self ):
76- if self .api .sign_in (self .username , self .password ):
77- self .config ['main' ]['username' ] = self .username
78- self .config ['main' ]['password' ] = self .password
79- self ._write_config_file ()
80- return True
81- else :
82- self .console .print ('[bold red]Incorrect username or password, please try again[/bold red]' )
83- return False
84-
85- def init (self ):
86- self .console .print (Panel ('[bold]Welcome to [dark_blue]Kroger[/dark_blue] CLI[/bold] (unofficial command line '
87- 'interface)' , box = box .ASCII ))
88-
89- if self .username is None and self .config ['main' ]['username' ] != '' :
90- self .username = self .config ['main' ]['username' ]
91- self .password = self .config ['main' ]['password' ]
0 commit comments