- import sqlite3, sys, time
- from database import *
- from datetime import datetime
- now = datetime.now()
-
- conn = sqlite3.connect('database.db')
- cursor = conn.cursor()
-
-
- dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
-
-
- def first_read_mid(uid, mid):
- print("---- FIRST READ OF USER -----")
- data = {"uid" : uid,
- "mid" : mid,
- "date" : dt_string,
- "chap" : 0 }
-
- print("UserID : %s" % data['uid'])
- print("MangID : %s" % data['mid'])
- print("Date : %s" % data['date'])
- print("Chap : %s" % 0)
- cursor.execute("""INSERT INTO readings(uid, mid, date, chap) VALUES(:uid, :mid, :date, :chap)""", data)
- conn.commit()
- return
-
- def get_last_read(uid, mid):
- cursor.execute("SELECT chap FROM readings WHERE uid = '{}' AND mid = '{}';".format(uid, mid) )
- rows = cursor.fetchall()
- if len(rows) == 0 :
- return 0
- return rows[0][0]
-
- def chapter_read_plus(uid, mid, number):
- username = get_dbusername(uid)
- title = get_dbtitle(mid)
- print("------ PLUS ------")
- print("User : %s" % str(username))
- print("Manga : %s" % str(mid))
- print("Last Read: %s " % get_last_read(uid, mid))
-
- if get_last_read(uid, mid) == 0 :
- print("No value in database, Need to create the column")
- first_read_mid(uid, mid)
-
- new_value = int(get_last_read(uid, mid)) + int(number)
- print("New Value : %s" % str(new_value))
- cursor.execute("UPDATE readings SET chap = '{}', date = '{}' WHERE mid = '{}' AND uid = '{}';".format(new_value, dt_string, mid, uid) )
- conn.commit()
- return
-
- def chapter_read_minus(uid, mid, number):
- username = get_dbusername(uid)
- title = get_dbtitle(mid)
- print("------ MINUS ------")
- print("User : %s" % str(username))
- print("Manga : %s" % str(mid))
- print("Last Read: %s " % get_last_read(uid, mid) )
-
- if get_last_read(uid, mid) == 0 :
- print("No value in database, Creating the column...")
- first_read_mid(uid, mid)
-
- return
-
- new_value = int(get_last_read(uid, mid)) - int(number)
- print("New Value : %s" % str(new_value))
-
- cursor.execute("UPDATE readings SET chap = '{}', date='{}' WHERE mid = '{}' AND uid = '{}';".format(new_value, dt_string, mid, uid) )
- conn.commit()
-
- def chapter_read_manual(uid, mid, chap):
- username = get_dbusername(uid)
- title = get_dbtitle(mid)
- print("------ MANUAL ------")
- print("User : %s" % str(username))
- print("Manga : %s" % str(mid))
- print("Chapter : %s" % str(chap))
- print("Last Read: %s " % get_last_read(uid, mid) )
-
- if get_last_read(uid, mid) == 0 :
- print("No value in database, Creating the column...")
- first_read_mid(uid, mid)
-
- if str(get_last_read(uid, mid)) == str(chap) :
- print("Vous avez deja lu ce chapitre")
- else :
- print("Vous n'avez pas vu le chapitre {} du manga {}".format(chap, title))
- cursor.execute("UPDATE readings SET chap = '{}', date='{}' WHERE mid = '{}' AND uid = '{}';".format(chap, dt_string, mid, uid) )
- conn.commit()
-
-
- def main():
- uid = input("UserID : ")
- mid = input("MangaID : ")
- chap = input("Chap : ")
- """chapter_read_minus(uid, mid, number)"""
- print(chapter_read_plus(uid, mid, chap))
-
-
- if __name__ == '__main__':
- try :
- main()
- except KeyboardInterrupt :
- print("CTRL+C, Exiting...")
- except IndexError :
- print("Bad values")
|