From cd426b4bad20cb29b85a77b3f5a5c892b2071521 Mon Sep 17 00:00:00 2001 From: Phuoc Cao Date: Wed, 29 Nov 2023 16:12:43 +0100 Subject: [PATCH] added cleanup function and logging --- .../clean_Nantes_anthologie_cinema_viet.htm | 374 +++++++++++++ .../static/temp/clean_www.icloud.com.html | 5 - html_cleanup/static/temp/errors_log | 3 + html_cleanup/static/temp/www.icloud.com.html | 496 ------------------ html_cleanup/templates/home.jinja2 | 10 +- html_cleanup/views/default.py | 37 +- 6 files changed, 409 insertions(+), 516 deletions(-) delete mode 100644 html_cleanup/static/temp/clean_www.icloud.com.html create mode 100644 html_cleanup/static/temp/errors_log delete mode 100644 html_cleanup/static/temp/www.icloud.com.html diff --git a/html_cleanup/static/temp/clean_Nantes_anthologie_cinema_viet.htm b/html_cleanup/static/temp/clean_Nantes_anthologie_cinema_viet.htm index 23b4f73..787a7d1 100644 --- a/html_cleanup/static/temp/clean_Nantes_anthologie_cinema_viet.htm +++ b/html_cleanup/static/temp/clean_Nantes_anthologie_cinema_viet.htm @@ -3,3 +3,377 @@ untitled + + + + +
+ + + +

+Festival des 3 Continents, Nantes 24.11 - 3.12 2023

+ + + +

+Anthologie du cinéma vietnamien

+ + + +

 

+ + + +

19 films vietnamiens + +de 1974 à 2022

+ + + +

 

+ + + +We will meet again

+ + + +

We will meet + +again / Đến hẹn lại lên - Tran Vu, 1974, 108’

+ + + +

Dimanche 26.11, + +18:30 - Vendredi 1.12, 13:45

+ + + +

 

+ + + +

Premier amour + / Mối tình đầu - Hai Ninh, 1977, 112’

+ + + +

Samedi 25.11, 13:45 + +- Jeudi 30.11, 20:30

+ + + +

 

+ + + +

The faces of may + / Tháng năm, những gương mặt- Dang Nhat Minh, 1975, 37’

+ + + +Nostalgie de la campagne

+ + + +

Nostalgie de la + +campagne / Thương nhớ đồng quê - Dang Nhat Minh, + +1995, 116’

+ + + +

Mercredi 29.11, + +20:30 - Vendredi 1.12, 17:00

+ + + +

 

+ + + +

Chom et Sa + / Chom và Sa - Pham Ky Nam, 1979, 70’

+ + + +

Dimanche 26.11, + +10:00 - Lundi 27.11, 16:15

+ + + +

 

+ + + +

Hanoi through + +whose eyes ? / Hà Nội trong mắt ai - Tran Van + +Thuy, 1982, 45’

+ + + +

The story of kindness + +or How to behave / Chuyện tử tế - Tran Van + +Thuy, 1987, 43’

+ + + +

Mardi 28.11, 16:00 - + +Dimanche 3.12, 10:30

+ + + +

 

+ + + +

Brothers + / Anh và em - Nguyen Huu Luyen & Tran Vu, 1986, 87’

+ + + +

Dimanche 26.11, 20:45 + +- Jeudi 30.11, 18:30

+ + + +

 

+ + + +

La fille du + +fleuve / Cô gái trên sông - Dang Nhat Minh, 1987, 100’

+ + + +

Samedi 25.11, 20:45 + +- Jeudi 30.11, 10:15

+ + + +

 

+ + + +

Troupe de cirque + +ambulant / Gánh xiếc rong - Viet Linh, 1988, 80’

+ + + +

Lundi 27.11, 17:30 - + +Dimanche 3.12, 17:30

+ + + +

 

+ + + +

Fairytale for a + +17-year-old girl /  Chuyện cổ tích cho tuổi 17 - + +Nguyen Xuan Son, 1988, 77’

+ + + +

Mercredi 29.11, + +13 :00 - Samedi 2.12, 13 :00

+ + + +

 

+ + + +

La lampe dans le + +rêve / Ngọn đèn trong mơ - Do Minh Tuan, 1988, 75’

+ + + +

Mardi 28.11, 10:15 - + +Vendredi 1.12, 18:45

+ + + +

 

+ + + +

Money, + +Money ! / Tiền ơi ! - Tran Vu & Nguyen + +Huu Luyen, 1989, 93’

+ + + +

Dimanche 26.11, + +15:30 - Samedi 2.12, 15:45

+ + + +

 

+ + + +

Enfance orageuse + / Tuổi thơ dữ dội - Nguyen Vinh Son, 1990, 135’

+ + + +

Lundi 27.11, 13:30 - + +Samedi 2.12, 20:30

+ + + +

 

+ + + +

PLease forgive me + / Hãy tha thứ cho em - Luu Trong Ninh, 1992, 90’

+ + + +

Lundi 27.11, 18:30 - + +Mercredi 29.11, 18:15

+ + + +

 

+ + + +

Piège d’amour + / Cạm bảy tình yêu - Pham Loc, 1992, 82’

+ + + +

Lundi 27.11, 10:30 - + +Mercredi 29.11, 14:45

+ + + +

 

+ + + +

In the lane + / Ngõ hẹp - Bach Diep, 1993, 98’

+ + + +

Samedi 25.11, 10:15 + +- Mardi 28.11, 14:00

+ + + +

 

+ + + +L’Immeuble

+ + + +

L’Immeuble + / Chung cư - Viet Linh, 1999, 90’

+ + + +

Samedi 25.11, 16:15 + +- Mercredi 29.11, 15:00

+ + + +

 

+ + + +Dust & metal

+ +

Dust & metal + / Cát bụi và kim loại - Esther Johnson, 2022, 83’

+ + + +

Vendredi 1.12, 20:30 + +- Dimanche 3.12, 18:00

+ + + +

 

+ + + +

Anthologie du cinéma vietnamien :

+ + + +

+https://www.3continents.com/fr/programme/2023/anthologie-du-cinema-vietnamien/

+ + + +

Programme 2023, horaires et lieux :

+ + + +

+https://www.3continents.com/wp-content/uploads/f3c-prog-2023-40p-net-planche.pdf

+ + + +

 

+ + + +

 

+ + + +

 

+ + + +

 

+ + + +
+ + + + + + + + + diff --git a/html_cleanup/static/temp/clean_www.icloud.com.html b/html_cleanup/static/temp/clean_www.icloud.com.html deleted file mode 100644 index 23b4f73..0000000 --- a/html_cleanup/static/temp/clean_www.icloud.com.html +++ /dev/null @@ -1,5 +0,0 @@ - - - -untitled - diff --git a/html_cleanup/static/temp/errors_log b/html_cleanup/static/temp/errors_log new file mode 100644 index 0000000..8d30082 --- /dev/null +++ b/html_cleanup/static/temp/errors_log @@ -0,0 +1,3 @@ +2023-11-29 11:40:58 - DSC03776.JPGERREUR: La taille du fichier dépasse la limite autorisée. Téléchargement refusé. +2023-11-29 11:44:29 - DSC03777.JPG - ERREUR: La taille du fichier dépasse la limite autorisée. Téléchargement refusé. +2023-11-29 11:45:44 - devis prothèse dentaire CKT.pdf - ERREUR: Le format du fichier n'est pas valide. Téléchargement refusé. diff --git a/html_cleanup/static/temp/www.icloud.com.html b/html_cleanup/static/temp/www.icloud.com.html deleted file mode 100644 index f7a55ae..0000000 --- a/html_cleanup/static/temp/www.icloud.com.html +++ /dev/null @@ -1,496 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - iCloud - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/html_cleanup/templates/home.jinja2 b/html_cleanup/templates/home.jinja2 index 2bcb185..f17c821 100644 --- a/html_cleanup/templates/home.jinja2 +++ b/html_cleanup/templates/home.jinja2 @@ -17,21 +17,21 @@
+ & Clean up
{% if file_url %} -

CLEANUP réussi

- Votre fichier nettoyé : {{ file_name }}: - Télécharger +

Cleanup réussi

+ Votre fichier nettoyé : {{ file_name }}

+ Télécharger {% endif %} {% endblock content %} diff --git a/html_cleanup/views/default.py b/html_cleanup/views/default.py index 1ef91d0..84abc52 100644 --- a/html_cleanup/views/default.py +++ b/html_cleanup/views/default.py @@ -4,6 +4,7 @@ import os import shutil import magic import sys +import datetime @view_config(route_name='home', renderer='html_cleanup:templates/home.jinja2') def home(request): @@ -33,17 +34,18 @@ def clean_html(input_file, output_file): # cleanup undesirable tags in html file encoding = "utf-8" message = "" - import pdb;pdb.set_trace() + # import pdb;pdb.set_trace() try: - with open(input_file, 'r', encoding='utf-8') as fi, open(output_file, 'w', encoding='utf-8') as fo: - fo.write("\n\n\nuntitled\n\n") + with open(output_file, 'w') as fo: + fo.write("\n\n\nuntitled\n\n".format(encoding)) body = False skip_tag = False nb_lines = 0 - for line_in in fi: + for line_in_bytes in input_file: + line_in = line_in_bytes.decode('utf-8') line_out = "" if not body: @@ -125,26 +127,41 @@ def process_file(request, input_file, input_name): # and if OK, process file message = '' ext_allowed = ['text/html', 'image/png', 'image/jpeg'] - max_size = 10 * (1024 ** 2) # 10 Mb + max_size = 5 * (1024 ** 2) # 10 Mb temp_folder = request.registry.settings['temp_folder'] + logfile_name = os.path.join(temp_folder, 'errors_log') mime = magic.from_buffer(input_file.read(), mime=True) # types de fichiers autorisés ? if mime not in ext_allowed: - message = "ERREUR: Le format du fichier n'est pas valide. Téléchargement refusé." + message = "Le format du fichier n'est pas valide. Téléchargement refusé." + add_error2log(logfile_name, input_name, message) else: # lire la taille du fichier - pos = input_file.tell() input_file.seek(0, 2) #seek to end filesize = input_file.tell() - input_file.seek(pos) # back to original position + input_file.seek(0) # back to original position # controler la taille du fichier if filesize > max_size: - message = "ERREUR: La taille du fichier dépasse la limite autorisée. Téléchargement refusé." + message = "La taille du fichier dépasse la limite autorisée. Téléchargement refusé." + add_error2log(logfile_name, input_name, message) else: # controle OK, traiter le fichier output_name = "clean_" + input_name output_file = os.path.join(temp_folder, output_name) message = clean_html(input_file, output_file) + if message: + add_error2log(logfile_name, input_name, message) + - return message \ No newline at end of file + return message + +def add_error2log(logfile_name, input_name, message): + # ecrire message d'erreur dans le log + + + # Get the current date and time + now = datetime.datetime.now() + with open(logfile_name, 'a', encoding='utf-8') as file: + line = now.strftime("%Y-%m-%d %H:%M:%S") + ' [' + input_name + '] ' + f'{message}\n' + file.write(line)