mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-04-27 07:03:35 +00:00
Simplified is_time_valid()
This commit is contained in:
parent
b6315f193c
commit
10616d6c88
8
twoot.py
8
twoot.py
@ -317,12 +317,12 @@ def contains_class(body_classes, some_class):
|
|||||||
return found
|
return found
|
||||||
|
|
||||||
|
|
||||||
def is_time_valid(timestamp, max_age, min_delay):
|
def is_time_valid(timestamp):
|
||||||
ret = True
|
ret = True
|
||||||
# Check that the tweet is not too young (might be deleted) or too old
|
# Check that the tweet is not too young (might be deleted) or too old
|
||||||
age_in_hours = (time.time() - float(timestamp)) / 3600.0
|
age_in_hours = (time.time() - float(timestamp)) / 3600.0
|
||||||
min_delay_in_hours = min_delay / 60.0
|
min_delay_in_hours = TOML['options']['tweet_delay'] / 60.0
|
||||||
max_age_in_hours = max_age * 24.0
|
max_age_in_hours = TOML['options']['tweet_max_age'] * 24.0
|
||||||
|
|
||||||
if age_in_hours < min_delay_in_hours or age_in_hours > max_age_in_hours:
|
if age_in_hours < min_delay_in_hours or age_in_hours > max_age_in_hours:
|
||||||
ret = False
|
ret = False
|
||||||
@ -596,7 +596,7 @@ def main(argv):
|
|||||||
timestamp = datetime.datetime.strptime(time_string, '%b %d, %Y · %I:%M %p %Z').timestamp()
|
timestamp = datetime.datetime.strptime(time_string, '%b %d, %Y · %I:%M %p %Z').timestamp()
|
||||||
|
|
||||||
# Check if time is within acceptable range
|
# Check if time is within acceptable range
|
||||||
if not is_time_valid(timestamp, TOML['options']['tweet_max_age'], TOML['options']['tweet_delay']):
|
if not is_time_valid(timestamp):
|
||||||
out_date_cnt += 1
|
out_date_cnt += 1
|
||||||
logging.debug("Tweet outside valid time range, skipping")
|
logging.debug("Tweet outside valid time range, skipping")
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user