A command line (CLI) program for monitoring and downloading 8chan threads. Licensed under MIT.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python3
  2. import sys
  3. import pkg_resources
  4. from lizard import db_methods
  5. version = pkg_resources.require("lizard")[0].version
  6. def help_info():
  7. print(""" _.-~` `~-.
  8. _.--~~~---,.__ _.,;; . -=(@'`\\
  9. .-` ``~~~~--~~` ';;; ____)
  10. _.' '. ';;;;; '`_.'
  11. .-~;` `\ ' ';;;;;__.~`
  12. .' .' `'. | / /;''
  13. \/ .---'''``) /'-._____.--'\ \\
  14. _/| (` / /` `\ \__
  15. ', `/- \ \ __/ (_ /-\-\-`
  16. `;'-..___) | `/-\-\-` Lizard
  17. `-. .' the 8chan monitor
  18. `~~~~`` v{}
  19. Usage: lizard [command] [options]
  20. Available commands:
  21. l - Lists all threads in database. Legend: ! - new replies, x - 404'd, Y - >(You).
  22. r - Refresh threads which are likely to receive new replies (to reduce unnecessary network activity).
  23. ra - Refresh all threads and update database.
  24. rl - Conservative refresh and list threads.
  25. ro - Conservative refresh and open threads with new replies in browsed.
  26. o - Open threads with new replies in the default browser. Will also update the "new replies"
  27. field accordingly.
  28. oa - Open all threads.
  29. p - Purge (remove) 404'd threads from database.
  30. b - Backup current database.
  31. e - Export list of threads. This will create a list of lizard add commands for all threads currently in the
  32. database. Useful for migrating between database versions.
  33. a - Add thread to database. Requires option (URL of the thread). Will also attempt to download
  34. the thread.
  35. d - Remove all instances of a thread (board & number) from the database.
  36. Example: "lizard d b 123" will remove thread >>>/b/123
  37. create - Create new database.
  38. """.format(version))
  39. exit()
  40. def main():
  41. n = len(sys.argv)
  42. if n < 2: help_info()
  43. command = sys.argv[1]
  44. if n == 2:
  45. if command == 'l':
  46. db_methods.check_database()
  47. db_methods.list_threads()
  48. elif command == 'ra':
  49. db_methods.check_database()
  50. db_methods.refresh_all_threads()
  51. elif command == 'r':
  52. db_methods.check_database()
  53. db_methods.refresh_all_threads(conservative=True)
  54. elif command == 'rl':
  55. db_methods.check_database()
  56. db_methods.refresh_all_threads(conservative=True)
  57. db_methods.list_threads()
  58. elif command == 'ro':
  59. db_methods.check_database()
  60. db_methods.refresh_all_threads(conservative=True)
  61. db_methods.open_threads_with_new_replies()
  62. elif command == 'o':
  63. db_methods.check_database()
  64. db_methods.open_threads_with_new_replies()
  65. elif command == 'oa':
  66. db_methods.check_database()
  67. db_methods.open_all_threads()
  68. elif command == 'p':
  69. db_methods.check_database()
  70. db_methods.remove_404_threads()
  71. elif command == 'c':
  72. db_methods.create_new_database()
  73. db_methods.check_database() # In case the DB creation is wrong
  74. elif command == 'b':
  75. # Not checking DB here, because there might be good reason to backup an invalid DB (eg. version conflict)
  76. db_methods.backup_database()
  77. elif command == 'e':
  78. db_methods.check_database()
  79. db_methods.export_thread_list()
  80. else:
  81. help_info()
  82. elif n == 3:
  83. if command == 'a':
  84. db_methods.check_database()
  85. db_methods.add_thread_to_db(sys.argv[2])
  86. else:
  87. help_info()
  88. elif n == 4:
  89. if command == 'd':
  90. db_methods.check_database()
  91. db_methods.remove_thread_by_id(sys.argv[2], sys.argv[3])
  92. else:
  93. help_info()
  94. else:
  95. help_info()
  96. if __name__ == '__main__':
  97. main()