Un serveur permettant de récupérer à quelle manga on s'est arrêté d'une licence. Un script se chargera de récupérer automatiquement les derniers mangas à jour à l'aide du site MangaDex
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reading.py 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import sqlite3, sys, time
  2. from database import *
  3. from datetime import datetime
  4. now = datetime.now()
  5. conn = sqlite3.connect('database.db')
  6. cursor = conn.cursor()
  7. dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
  8. def first_read_mid(uid, mid):
  9. print("---- FIRST READ OF USER -----")
  10. data = {"uid" : uid,
  11. "mid" : mid,
  12. "date" : dt_string,
  13. "chap" : 0 }
  14. print("UserID : %s" % data['uid'])
  15. print("MangID : %s" % data['mid'])
  16. print("Date : %s" % data['date'])
  17. print("Chap : %s" % 0)
  18. cursor.execute("""INSERT INTO readings(uid, mid, date, chap) VALUES(:uid, :mid, :date, :chap)""", data)
  19. conn.commit()
  20. return
  21. def get_last_read(uid, mid):
  22. cursor.execute("SELECT chap FROM readings WHERE uid = '{}' AND mid = '{}';".format(uid, mid) )
  23. rows = cursor.fetchall()
  24. if len(rows) == 0 :
  25. return 0
  26. return rows[0][0]
  27. def chapter_read_plus(uid, mid, number):
  28. username = get_dbusername(uid)
  29. title = get_dbtitle(mid)
  30. print("------ PLUS ------")
  31. print("User : %s" % str(username))
  32. print("Manga : %s" % str(mid))
  33. print("Last Read: %s " % get_last_read(uid, mid))
  34. if get_last_read(uid, mid) == 0 :
  35. print("No value in database, Need to create the column")
  36. first_read_mid(uid, mid)
  37. new_value = int(get_last_read(uid, mid)) + int(number)
  38. print("New Value : %s" % str(new_value))
  39. cursor.execute("UPDATE readings SET chap = '{}', date = '{}' WHERE mid = '{}' AND uid = '{}';".format(new_value, dt_string, mid, uid) )
  40. conn.commit()
  41. return
  42. def chapter_read_minus(uid, mid, number):
  43. username = get_dbusername(uid)
  44. title = get_dbtitle(mid)
  45. print("------ MINUS ------")
  46. print("User : %s" % str(username))
  47. print("Manga : %s" % str(mid))
  48. print("Last Read: %s " % get_last_read(uid, mid) )
  49. if get_last_read(uid, mid) == 0 :
  50. print("No value in database, Creating the column...")
  51. first_read_mid(uid, mid)
  52. return
  53. new_value = int(get_last_read(uid, mid)) - int(number)
  54. print("New Value : %s" % str(new_value))
  55. cursor.execute("UPDATE readings SET chap = '{}' WHERE mid = '{}' AND uid = '{}';".format(new_value, mid, uid) )
  56. conn.commit()
  57. def chapter_read_manual(uid, mid, chap):
  58. username = get_dbusername(uid)
  59. title = get_dbtitle(mid)
  60. print("------ MANUAL ------")
  61. print("User : %s" % str(username))
  62. print("Manga : %s" % str(mid))
  63. print("Chapter : %s" % str(chap))
  64. print("Last Read: %s " % get_last_read(uid, mid) )
  65. if str(get_last_read(uid, mid)) == str(chap) :
  66. print("Vous avez deja lu ce chapitre")
  67. else :
  68. print("Vous n'avez pas vu le chapitre {} du manga {}".format(chap, title))
  69. cursor.execute("UPDATE readings SET chap = '{}' WHERE mid = '{}' AND uid = '{}';".format(chap, mid, uid) )
  70. conn.commit()
  71. def main():
  72. uid = input("UserID : ")
  73. mid = input("MangaID : ")
  74. number = input("Nombre : ")
  75. """chapter_read_minus(uid, mid, number)"""
  76. print(chapter_read_plus(uid, mid, number))
  77. if __name__ == '__main__':
  78. try :
  79. main()
  80. except KeyboardInterrupt :
  81. print("CTRL+C, Exiting...")
  82. except IndexError :
  83. print("Bad values")