[reddit] move date-min/-max handling into Extractor class

This commit is contained in:
Mike Fährmann
2019-07-16 22:54:39 +02:00
parent fb875d1ab8
commit 09f37fde39
2 changed files with 16 additions and 15 deletions

View File

@@ -13,6 +13,7 @@ import time
import netrc
import queue
import logging
import datetime
import requests
import threading
import http.cookiejar
@@ -217,6 +218,20 @@ class Extractor():
return False
return True
def _get_date_min_max(self, dmin=None, dmax=None):
"""Retrieve and parse 'date-min' and 'date-max' config values"""
def get(key, default):
ts = self.config(key, default)
if isinstance(ts, str):
try:
ts = int(datetime.datetime.strptime(ts, fmt).timestamp())
except ValueError as exc:
self.log.warning("Unable to parse '%s': %s", key, exc)
ts = default
return ts
fmt = self.config("date-format", "%Y-%m-%dT%H:%M:%S")
return get("date-min", dmin), get("date-max", dmax)
@classmethod
def _get_tests(cls):
"""Yield an extractor's test cases as (URL, RESULTS) tuples"""