Browse Source

Refactored methods for opening threads in browser to reduce repetition.

master
Abrax 3 years ago
parent
commit
56bd11e093
2 changed files with 9 additions and 19 deletions
  1. 3
    3
      lizard/__init__.py
  2. 6
    16
      lizard/db_methods.py

+ 3
- 3
lizard/__init__.py View File

@@ -67,13 +67,13 @@ def main():
elif command == 'ro':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)
db_methods.open_threads_with_new_replies()
db_methods.open_threads(True)
elif command == 'o':
db_methods.check_database()
db_methods.open_threads_with_new_replies()
db_methods.open_threads(True)
elif command == 'oa':
db_methods.check_database()
db_methods.open_all_threads()
db_methods.open_threads(False)
elif command == 'p':
db_methods.check_database()
db_methods.remove_404_threads()

+ 6
- 16
lizard/db_methods.py View File

@@ -164,8 +164,12 @@ def refresh_all_threads(conservative=False):
print('Done!')


def open_threads_with_new_replies():
threads = Thread.select().where(Thread.is_up and Thread.new_replies)
def open_threads(only_threads_with_new_replies=True):
if not only_threads_with_new_replies:
threads = Thread.select()
else:
threads = Thread.select().where(Thread.is_up and Thread.new_replies)

print('Opening {} threads in browser.'.format(len(threads)))

for t in threads:
@@ -181,20 +185,6 @@ def open_threads_with_new_replies():
t.save()


def open_all_threads():
threads = Thread.select()
print('Opening {} threads in browser.'.format(len(threads)))

for t in threads:
thread_url = t.original_url

webbrowser.open(thread_url)

t.new_replies = 0
t.last_seen = time_methods.timestamp_now()
t.save()


def remove_404_threads():
threads = Thread.select().where(Thread.is_up == 0)
print('Removing {} entries.'.format(len(threads)))

Loading…
Cancel
Save