diff --git a/create_manga.py b/create_manga.py new file mode 100644 index 0000000..1f22648 --- /dev/null +++ b/create_manga.py @@ -0,0 +1,23 @@ +# coding: utf-8 +from mangadex import * +import sqlite3 + +conn = sqlite3.connect('database.db') +cursor = conn.cursor() + +url = "https://mangadex.org/title/31477" + +def create_manga(url): + data = {"id" : get_id(url), + "title" : get_title(url), + "author" : get_author(url), + "url" : url, + "chap" : get_last_chap(url)} + + print("Id : " + str(data["id"])) + print("Title : " + str(data["title"])) + print("Author : " + str(data["author"])) + print("Link : " + 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() diff --git a/database.db b/database.db new file mode 100644 index 0000000..92b32e2 Binary files /dev/null and b/database.db differ diff --git a/login.py b/login.py new file mode 100644 index 0000000..bd66c47 --- /dev/null +++ b/login.py @@ -0,0 +1,31 @@ +# coding: utf-8 + +import sqlite3 +import hashlib + +conn = sqlite3.connect('database.db') +cursor = conn.cursor() + + +def main(): + + login = input("Veuillez entrer un utilisateur : ") + password = input("Veuillez entrer un mot de passe : ") + + str2hash = password + result = hashlib.md5(str2hash.encode()) + hash_input = result.hexdigest() + print("Hash MD5 de votre mot de passe : %s" % hash_input) + + cursor.execute("SELECT password FROM users WHERE username = '%s';" % login) + + rows = cursor.fetchall() + stored_password = str(rows[0][0]) + if stored_password == hash_input : + print("Mot de passe correct") + else : + print("Mot de passe incorrect") + + +if __name__ == '__main__': + main() diff --git a/mangadex.py b/mangadex.py new file mode 100644 index 0000000..e5c8d9b --- /dev/null +++ b/mangadex.py @@ -0,0 +1,63 @@ + +import urllib.request +from bs4 import BeautifulSoup + +url = "https://mangadex.org/title/31477" + +def get_title(url): + fp = urllib.request.urlopen(url) + mybytes = fp.read() + html = mybytes.decode("utf8") + fp.close() + soup = BeautifulSoup(html, "html5lib") + + for code in soup.find('title'): + title = code + title = title[:-18] + return title + +def get_author(url): + fp = urllib.request.urlopen(url) + mybytes = fp.read() + html = mybytes.decode("utf8") + fp.close() + soup = BeautifulSoup(html, "html5lib") + + dict = soup.find('a', {'title' : 'Other manga by this author'}) + author = str(dict).split('"')[4][1:][:-4] + return author + + +def get_id(url): + id = url.split('/')[4] + return id + +def get_url(id): + id_url = "https://mangadex.org/title/%s" % id + return id_url + +def get_last_chap(url): + fp = urllib.request.urlopen(url) + mybytes = fp.read() + html = mybytes.decode("utf8") + fp.close() + soup = BeautifulSoup(html, "html5lib") + + chap = soup.find('a', {'class' : 'text-truncate'}) + chap = str(chap).split('Ch. ') + chap = chap[1][:-4] + chap = [int(s) for s in chap.split() if s.isdigit()] + return chap[0] + +def main(): + title = get_title(url) + print("Titre de l'anime : %s " % title) + author = get_author(url) + print("Auteur de l'anime : %s " % author) + id = get_id(url) + print("ID Mangadex : %s " % id) + chap = get_last_chap(url) + print("Dernier chap : %s " % chap) + link = get_url(get_id(url)) + print("Url mangadex : %s" % link) +main() diff --git a/update_manga.py b/update_manga.py new file mode 100644 index 0000000..e56568f --- /dev/null +++ b/update_manga.py @@ -0,0 +1,30 @@ +# coding: utf-8 +from mangadex import * +import sqlite3 + +conn = sqlite3.connect('database.db') +cursor = conn.cursor() + + + + + +def update_manga(id): + url = get_url(id) + cursor.execute("SELECT chap FROM manga WHERE id = '%s'" % id) + + rows = cursor.fetchall() + last_chapt = str(rows[0][0]) + 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) : + print("Nous sommes a jour") + else : + print("Pas a jour ! :c ") + cursor.execute("UPDATE manga SET chap = '{}' WHERE id = '{}'".format(get_last_chap(url), get_id(url))) + conn.commit() + + + +update_manga(31477)