Browse Source

Fixes #35 + readme update

master
Abrax 6 years ago
parent
commit
c0eb2bcae9
  1. 16
      README.md
  2. 12
      lizard/__init__.py
  3. 36
      lizard/db_methods.py

16
README.md

@ -25,14 +25,18 @@ You can call `lizard r` to refresh threads currently in the database, and see th @@ -25,14 +25,18 @@ You can call `lizard r` to refresh threads currently in the database, and see th
### 0.4 (in development)
This version will change syntax for some commands:
Command syntax changes:
- Listing threads:
- `lizard la` (list all) will produce the previous `lizard l` functionality.
- `lizard l` will list only items that have had something interesting happen (reply or 404).
- `lizard rl` will print the summary list.
- Listing threads:
- `lizard la` (list all) will produce the previous `lizard l` functionality.
- `lizard l` will list only items that have had something interesting happen (reply or 404).
- `lizard rl` will print the summary list.
Tor features:
- `lizard tor` will now auto-open the tor captcha page for convenience. ([#42](https://git.teknik.io/abrax/lizard/issues/42))
Bugfixes:
- `lizard create` command now working. ([#43](https://git.teknik.io/abrax/lizard/issues/45))
These changes take effect with version 0.4 so be ready to update your scripts!
### 0.3 (current)

12
lizard/__init__.py

@ -26,7 +26,8 @@ def help_info(): @@ -26,7 +26,8 @@ def help_info():
Usage: lizard [command] [options]
Available commands:
l - Lists all threads in database. Legend: ! - new replies, x - 404'd, Y - >(You).
la - Lists all threads in database. Legend: ! - new replies, x - 404'd, Y - >(You).
l - Lists only threads that have activity.
r - Refresh threads which are likely to receive new replies (to reduce unnecessary network activity).
ra - Refresh all threads and update database.
rl - Conservative refresh and list threads.
@ -54,9 +55,12 @@ def main(): @@ -54,9 +55,12 @@ def main():
if n < 2: help_info()
command = sys.argv[1]
if n == 2:
if command == 'l':
if command == 'la':
db_methods.check_database()
db_methods.list_threads()
db_methods.list_threads(interesting_only=False)
elif command == 'l':
db_methods.check_database()
db_methods.list_threads(interesting_only=True)
elif command == 'ra':
db_methods.check_database()
db_methods.refresh_all_threads()
@ -66,7 +70,7 @@ def main(): @@ -66,7 +70,7 @@ def main():
elif command == 'rl':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)
db_methods.list_threads()
db_methods.list_threads(interesting_only=True)
elif command == 'ro':
db_methods.check_database()
db_methods.refresh_all_threads(conservative=True)

36
lizard/db_methods.py

@ -94,9 +94,14 @@ def remove_thread_by_id(board, thread_no): @@ -94,9 +94,14 @@ def remove_thread_by_id(board, thread_no):
print('{} entries removed.'.format(len(threads_to_remove)))
def list_threads():
threads = Thread.select().order_by(Thread.last_reply_time)
def list_threads(interesting_only=False):
""" Lists the threads currently being watched as a table.
An "interesting" thread is one in which some activity has happened, such as new replies or going 404. These will
be indicated by a symbol.
"""
threads = Thread.select().order_by(Thread.last_reply_time)
now = time_methods.timestamp_now()
format_string = '{} {:<50}{:<20}{:<20}{:<20}'
@ -113,14 +118,15 @@ def list_threads(): @@ -113,14 +118,15 @@ def list_threads():
else:
mark = ' '
s = format_string.format(
mark,
t.original_url,
humanize.naturaldelta(now - t.last_reply_time),
humanize.naturaldelta(now - t.last_seen),
humanize.naturaldelta(now - t.last_refreshed)
)
print(s)
if (mark != ' ') or (not interesting_only):
s = format_string.format(
mark,
t.original_url,
humanize.naturaldelta(now - t.last_reply_time),
humanize.naturaldelta(now - t.last_seen),
humanize.naturaldelta(now - t.last_refreshed)
)
print(s)
def refresh_all_threads(conservative=False):
@ -132,7 +138,8 @@ def refresh_all_threads(conservative=False): @@ -132,7 +138,8 @@ def refresh_all_threads(conservative=False):
print('Doing conservative refresh')
# TODO: The more natural form of this expression is (now - Thread.last_refreshed) / (now - Thread.last_reply_time) > 0.01 but for some reason that always gets rounded to zero
threads = threads.where((now - Thread.last_reply_time) / (now - Thread.last_refreshed) < conservative_refresh_criterion)
threads = threads.where(
(now - Thread.last_reply_time) / (now - Thread.last_refreshed) < conservative_refresh_criterion)
print('Refreshing {} threads...'.format(len(threads)))
for t in threads:
@ -145,8 +152,11 @@ def refresh_all_threads(conservative=False): @@ -145,8 +152,11 @@ def refresh_all_threads(conservative=False):
new_replies = [i for i in replies if int(i['last_modified']) > t.last_refreshed]
replies_to_anchored = [i for i in new_replies if ('&gt;&gt;{}'.format(t.anchored_reply) in i['com'])]
print('/{}/{} has {} new posts'.format(t.board, t.thread_no, len(new_replies), len(replies_to_anchored)), end='')
print(" and {} >(You)'s".format(len(replies_to_anchored))) if len(replies_to_anchored) > 0 else print('!')
print(
'/{}/{} has {} new posts'.format(t.board, t.thread_no, len(new_replies), len(replies_to_anchored)),
end='')
print(" and {} >(You)'s".format(len(replies_to_anchored))) if len(replies_to_anchored) > 0 else print(
'!')
t.new_replies = len(new_replies)
t.oldest_new_reply = get_oldest_reply(new_replies)

Loading…
Cancel
Save