can now modify entries in animelist.csv
This commit is contained in:
parent
e24f4911db
commit
77a6465254
@ -26,3 +26,18 @@
|
||||
<input type = "text" name = "del_field" />
|
||||
<input type = "submit" value = "submit" />
|
||||
</form>
|
||||
|
||||
<form action="mod_animu" method = "POST">
|
||||
<p>Vuoi modificare un anime?</p>
|
||||
<table id="mod_animu_table">
|
||||
<tr>
|
||||
<td>Index:</td><td><input type = "text" name = "field_1_index" /></td>
|
||||
<td>Url:</td><td><input type = "text" name = "field_1_url" /></td>
|
||||
<td>Cartella:</td><td><input type = "text" name = "field_1_folder" /></td>
|
||||
<td>Nome Ep:</td><td><input type = "text" name = "field_1_name" /></td>
|
||||
<td>Abilitato:</td><td><input type = "text" name = "field_1_check" /></td>
|
||||
<td>JellyNaming:</td><td><input type = "text" name = "field_1_naming" /></td>
|
||||
<td><input type = "submit" value = "submit" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
57
webserver.py
57
webserver.py
@ -22,8 +22,8 @@ def new_animu():
|
||||
if request.method == 'POST':
|
||||
form_data = request.form
|
||||
#print(form_data)
|
||||
if add_animu(form_data):
|
||||
return f'Anime aggiunto con successo'
|
||||
if add_animu_fun(form_data):
|
||||
return redirect('/')
|
||||
return f'Errore aggiungendo anime, hai inserito correttamente i valori?'
|
||||
|
||||
@app.route("/del_animu", methods = ['POST', 'GET'])
|
||||
@ -33,11 +33,23 @@ def del_animu():
|
||||
if request.method == 'POST':
|
||||
form_data = request.form
|
||||
print(form_data)
|
||||
if del_animu(form_data):
|
||||
return f'Anime rimosso con successo'
|
||||
if del_animu_fun(form_data):
|
||||
return redirect('/')
|
||||
return f'Errore rimuovendo anime, hai inserito correttamente i valori?'
|
||||
|
||||
def add_animu(form_data):
|
||||
@app.route("/mod_animu", methods = ['POST', 'GET'])
|
||||
def mod_animu():
|
||||
if request.method == 'GET':
|
||||
return redirect('/')
|
||||
if request.method == 'POST':
|
||||
form_data = request.form
|
||||
print(form_data)
|
||||
if mod_animu_fun(form_data):
|
||||
return redirect('/')
|
||||
return f'Errore modificando anime, hai inserito correttamente i valori?'
|
||||
|
||||
|
||||
def add_animu_fun(form_data):
|
||||
try:
|
||||
if not (form_data['field_season'] and form_data['field_url'] and form_data['field_folder']):
|
||||
return False
|
||||
@ -55,7 +67,7 @@ def add_animu(form_data):
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def del_animu(form_data):
|
||||
def del_animu_fun(form_data):
|
||||
try:
|
||||
if not form_data['del_field']:
|
||||
return False
|
||||
@ -74,5 +86,38 @@ def del_animu(form_data):
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def mod_animu_fun(form_data):
|
||||
try:
|
||||
index = int(form_data['field_1_index'])
|
||||
url = form_data['field_1_url']
|
||||
folder = form_data['field_1_folder']
|
||||
name = form_data['field_1_name']
|
||||
check = form_data['field_1_check']
|
||||
naming = form_data['field_1_naming']
|
||||
if not ((check in '01') and (naming in '01')):
|
||||
return False
|
||||
newrow = [url,folder,name,check[-1:],naming[-1:]]
|
||||
if not index: #cosi non si può modificare la riga 0
|
||||
return False
|
||||
data = []
|
||||
with open("animelist.csv", 'r', newline='') as file:
|
||||
csv_reader = csv.reader(file)
|
||||
for ind, row in enumerate(csv_reader):
|
||||
if ind != index:
|
||||
data.append(row)
|
||||
else: #cosi se lindex dato è fuori dal range non si fanno modifiche
|
||||
for i in range(len(newrow)):
|
||||
if newrow[i] == '':
|
||||
newrow[i]=row[i]
|
||||
data.append(newrow)
|
||||
# Write the remaining data back to the CSV file
|
||||
with open("animelist.csv", 'w', newline='') as file:
|
||||
csv_writer = csv.writer(file)
|
||||
csv_writer.writerows(data)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(HOST_NAME, HOST_PORT)
|
||||
|
Loading…
Reference in New Issue
Block a user