Browse Source

Fixed #16

master
Abrax 3 years ago
parent
commit
af1ff5ac30
3 changed files with 33 additions and 2 deletions
  1. 1
    0
      README.md
  2. 19
    2
      db_methods.py
  3. 13
    0
      lizard.py

+ 1
- 0
README.md View File

@@ -21,6 +21,7 @@ These changes take effect with version 0.3 so be ready to update your scripts!
* New command: `rl` is refresh + list
* New command: `ro` is refresh + open in browser
* `c` and `b` now print more useful output.
* Better handling of non-existent/invalid database.

### 0.1.1


+ 19
- 2
db_methods.py View File

@@ -3,16 +3,33 @@ import shutil
import webbrowser
import humanize
import db_model
import file_io
import time_methods
import web_methods
from db_model import Thread, db
from db_model import Thread
from file_io import path_to_database, ensure_directory_exists, timestamped_path_to_exported_threads_file
from json_methods import time_of_last_reply, get_oldest_reply
from web_methods import fetch_and_parse_thread_json, dump_thread_html, dump_thread_files, parse_url

conservative_refresh_criterion = 10


def check_database():
""" Checks the database. If a problem is found, prints an error message and terminates program.

Watch out! This does NOT necessarily check every possible problem with the database. """
p = path_to_database()

if not os.path.exists(p):
print('{} does not exist. Try running "lizard c" to create a new one.'.format(p))
exit()

# This only ensures that a table named thread exists, doesn't check if it has the right columns.
if not Thread.table_exists():
print('{} does not have the correct table. Try moving it elsewhere, and running "lizard c" to create a '
'fresh database.'.format(p))
exit()


def create_new_database():
"""Creates a new database. Will fail if database already exists."""
p = path_to_database()

+ 13
- 0
lizard.py View File

@@ -51,38 +51,51 @@ def main():
command = sys.argv[1]
if n == 2:
if command == 'l':
db_methods.check_database()
db_methods.list_threads()
elif command == 'r':
db_methods.check_database()
db_methods.refresh_all_threads()
elif command == 'rc':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)
elif command == 'rl':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)
db_methods.list_threads()
elif command == 'ro':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)
db_methods.open_threads_with_new_replies()
elif command == 'o':
db_methods.check_database()
db_methods.open_threads_with_new_replies()
elif command == 'oa':
db_methods.check_database()
db_methods.open_all_threads()
elif command == 'p':
db_methods.check_database()
db_methods.remove_404_threads()
elif command == 'c':
db_methods.create_new_database()
db_methods.check_database() # In case the DB creation is wrong
elif command == 'b':
# Not checking DB here, because there might be good reason to backup an invalid DB (eg. version conflict)
db_methods.backup_database()
elif command == 'e':
db_methods.check_database()
db_methods.export_thread_list()
else:
help_info()
elif n == 3:
if command == 'a':
db_methods.check_database()
db_methods.add_thread_to_db(sys.argv[2])
else:
help_info()
elif n == 4:
if command == 'd':
db_methods.check_database()
db_methods.remove_thread_by_id(sys.argv[2], sys.argv[3])
else:
help_info()

Loading…
Cancel
Save