-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
165 lines (130 loc) · 4.62 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#----- Inicio de appliacion
import os
import csv
clear= lambda: os.system('cls')
CLIENT_TABLE='.clients_info.csv'
CLIENT_SCHEMA=['name','company', 'email', 'position']
clients=[]
clear()
def _initialize_clients_from_storage():
with open (CLIENT_TABLE,mode='r') as input_file:
reader= csv.DictReader(input_file,fildnames=CLIENT_SCHEMA)
for row in reader:
clients.append(row)
def _save_clients_to_storage():
tmp_table_name='{}.tmp'.format(CLIENT_TABLE)
with open (tmp_table_name, mode='w') as tem_file:
writer= csv.DictWriter(tem_file,fieldnames=CLIENT_TABLE)
writer.writerows(clients)
os.remove(CLIENT_TABLE)
os.rename(tmp_table_name,CLIENT_TABLE)
def _get_client_name():
return input('Enter the client name: ')
def create_client():
client_name= _get_client_name()
new_client(client_name)
print('{} was succesfully created'.format(client_name))
def new_client(client_name):
""" Este es un texto de ayuda para esta funcion """
global clients
clients.append(client_name)
def delete_client():
global clients
list_clients()
client_name= _get_client_name()
if client_name in clients:
clients.remove(client_name)
print('{} was succesfully deleted'.format(client_name))
else:
print('{} was not found on client list '.format(client_name))
list_clients()
def update_client():
global clients
list_clients()
client_name= _get_client_name()
if client_name in clients:
index= clients.index(client_name)
updated_client_name= input('{} was found, enter it\'s new name: '.format(client_name))
clients[index]= updated_client_name
else:
print('{} was not found on client list unable to update'.format(client_name))
list_clients()
def list_clients():
global clients
for idx ,client in enumerate(clients):
print('{}: {}'.format(idx,client))
def save():
_save_clients_to_storage()
def not_valid():
input('COMMAND NOT VALID PRESS ENTER AND TRY AGAIN')
def select(command,options):
""" allowd to a function on a variable options [dir] which stores the functions names """
command=command.upper()
func = options.get(command, "not_valid") # function selected based
return func+'()'
def nothing():
pass
def end():
pass
#---------------MAIN--------------------------------
if __name__ == '__main__':
_initialize_clients_from_storage()
with open('welcome_message.txt','r') as welcome_f:
welcome_banner=welcome_f.read()
input_file=open('list.txt','r+')
input_text=input_file.read()
clients=input_text.split(', ')
main_menu= { 'C': 'create_client', 'D': 'delete_client','L':'list_clients', 'U':'update_client','S': 'save','Q':'end'}
yes_no={'Y':'save' , 'N': 'end'}
while True:
command= str(input(welcome_banner))
clear()
func=select(command,main_menu)
if func=='end()':
command=str(input('you are about to close the application. do you want to save changes? \n Yes\\No \n'))
save_func=select(command,yes_no)
exec(save_func)
if save_func=='"not_valid':
pass
else:
break
exec(func)
pass
print(clients)
welcome_f.close()
input_file.close()
# Notas
# funcion dir() y help() permite conocer todas la funciones que puede hacer una variable
# [inicio:final:paso]
# ---------GIT-----------------
# git config --global user.name ""
# ssh-keygen -t rsa -b 4096 -C "[email protected]"
# eval $( ssh-agent -s) esta corriendo el agente ssh
# ssh-add ~/.ssh/id_rsa
# git location
# /e/Documentos/codigo/platzi/python/CRUD_app
# git log --stat
# git status
# git diff [commit_id] [commit_id]
# git checkout [commit_id]
# git reset HEAD quita los archivos de stage
# git clone [url]
# git push enviar
# git fetch
# git merge
# git pull = fetch + merge
# branch experiment rama experimental
# git switch experiment
# git remote add origin [url]
# git remote -v
# git push origin master git push [to_there] [from_here]
# git pull origin master git pull [from_there] [to_here]
# git pull origin master --allow-unrelated-histories
# git remote set-url origin [ssh direction] [email protected]:jsduenass/CRUD_app.git
# alias git_history=git log --all --graph --decorate --oneline
# git tag -a v0.1 - m "commint message" [commit_id]
# git tag -d [tag_name]
#git push origin --tag
# gitk show branch history
#terminal.integrated.shell.* can only be defined in user settings and not at workspace scope
#git config --global core.editor "code"