From 08b65587196d2cfce2d306159f9ebe296a59614b Mon Sep 17 00:00:00 2001 From: Cinabre Date: Wed, 16 Dec 2020 11:59:50 +0100 Subject: [PATCH] Ajout de commentaire + creation de la fonction "get_url" --- create_manga.py | 19 ++++++++++++++++++- mangadex.py | 4 +++- update_manga.py | 18 ++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/create_manga.py b/create_manga.py index 1f22648..2c782f7 100644 --- a/create_manga.py +++ b/create_manga.py @@ -1,13 +1,17 @@ # coding: utf-8 from mangadex import * -import sqlite3 +import sqlite3, sys conn = sqlite3.connect('database.db') cursor = conn.cursor() url = "https://mangadex.org/title/31477" +def check_if_exit(url): + id = get_id(url) + def create_manga(url): + data = {"id" : get_id(url), "title" : get_title(url), "author" : get_author(url), @@ -21,3 +25,16 @@ 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/mangadex.py b/mangadex.py index e5c8d9b..e548ecd 100644 --- a/mangadex.py +++ b/mangadex.py @@ -60,4 +60,6 @@ def main(): print("Dernier chap : %s " % chap) link = get_url(get_id(url)) print("Url mangadex : %s" % link) -main() + +if __name__ == '__main__': + main() diff --git a/update_manga.py b/update_manga.py index e56568f..9294b1c 100644 --- a/update_manga.py +++ b/update_manga.py @@ -5,26 +5,28 @@ import sqlite3 conn = sqlite3.connect('database.db') cursor = conn.cursor() - - - +def main(): + print("Pas de fonction Main") def update_manga(id): url = get_url(id) + # On récupère l'URL + cursor.execute("SELECT chap FROM manga WHERE id = '%s'" % id) rows = cursor.fetchall() + # Last_chapt est le dernier chapitre sauvegardé last_chapt = str(rows[0][0]) + 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)) - if int(last_chapt) == get_last_chap(url) : + if int(last_chapt) == int(get_last_chap(url)) : print("Nous sommes a jour") else : - print("Pas a jour ! :c ") + 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() - - -update_manga(31477) +if __name__ == '__main__': + main()