From 3c900b5f6ba0b53f8b66cc7db1975901fecd6824 Mon Sep 17 00:00:00 2001 From: Cinabre Date: Wed, 16 Dec 2020 12:09:12 +0100 Subject: [PATCH] =?UTF-8?q?Reduction=20du=20nombre=20d'appel=20web=20n?= =?UTF-8?q?=C3=A9c=C3=A9ssaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- create_manga.py | 8 ++++++-- update_manga.py | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/create_manga.py b/create_manga.py index 2c782f7..19b290e 100644 --- a/create_manga.py +++ b/create_manga.py @@ -9,9 +9,9 @@ url = "https://mangadex.org/title/31477" def check_if_exit(url): id = get_id(url) - -def create_manga(url): + +def create_manga(url): data = {"id" : get_id(url), "title" : get_title(url), "author" : get_author(url), @@ -25,16 +25,20 @@ def create_manga(url): print("Last chap" + str(data["chap"])) cursor.execute(""" INSERT INTO manga(id, title, author, url, chap) VALUES(:id, :title, :author, :url, :chap)""", data) conn.commit() + def main(): if len(sys.argv) == 2 : print("Mode Script") url = sys.argv[1] print("URL : %s" % url) + + else : print("Mode utilisateur") url = input("Veuillez entrer l'URL du manga : ") print("URL : %s" % url) + if __name__ == '__main__': main() diff --git a/update_manga.py b/update_manga.py index 9294b1c..48e7216 100644 --- a/update_manga.py +++ b/update_manga.py @@ -6,7 +6,8 @@ conn = sqlite3.connect('database.db') cursor = conn.cursor() def main(): - print("Pas de fonction Main") + #print("Pas de fonction Main") + update_manga(31477) def update_manga(id): url = get_url(id) @@ -17,14 +18,16 @@ def update_manga(id): rows = cursor.fetchall() # Last_chapt est le dernier chapitre sauvegardé last_chapt = str(rows[0][0]) + + new_chapt = get_last_chap(url) print("Mise a jour de %s" % get_title(url)) print("Le dernier chapitre est %s" % last_chapt) - print("Le dernier chapitre enregistre est %s" % get_last_chap(url)) + print("Le dernier chapitre sur mangadex est %s" % new_chapt) - if int(last_chapt) == int(get_last_chap(url)) : + if int(last_chapt) == int(new_chapt) : print("Nous sommes a jour") else : - print("Pas a jour ! Le dernier chapitre est %s " ) + print("Pas a jour ! Le dernier chapitre est %s " % ) cursor.execute("UPDATE manga SET chap = '{}' WHERE id = '{}'".format(get_last_chap(url), get_id(url))) conn.commit()