This commit is contained in:
j 2019-08-05 12:19:24 +02:00
parent a131c78482
commit ee9e430ef8
2 changed files with 12 additions and 5 deletions

View file

@ -136,7 +136,7 @@ def parse_cast(string):
results[rkey] = cast[key].split(', \n') results[rkey] = cast[key].split(', \n')
return results return results
def update_ids(year, month=None, day=None, sort=None, expexted=None): def update_ids(year, month=None, day=None, sort=None, expected=None):
films = {} films = {}
if day is not None: if day is not None:
url = get_day(year, month, day) url = get_day(year, month, day)
@ -155,8 +155,8 @@ def update_ids(year, month=None, day=None, sort=None, expexted=None):
else: else:
urls = [url] urls = [url]
if not expexted: if not expected:
expexted = get_film_count(year, month, day) expected = get_film_count(year, month, day)
for url in urls: for url in urls:
data = read_url(url, timeout=TIMEOUT) data = read_url(url, timeout=TIMEOUT)
@ -171,7 +171,7 @@ def update_ids(year, month=None, day=None, sort=None, expexted=None):
has_after = re.compile(after_link).findall(data) has_after = re.compile(after_link).findall(data)
if has_next: if has_next:
n = '%s&start=%s' % (url, start) n = '%s&start=%s' % (url, start)
elif sort != 'alpha' and start > MAX_PER_RANGE and has_after: elif sort != 'alpha' and has_after:
n = '%s%s' % (base_url, has_after[0]) n = '%s%s' % (base_url, has_after[0])
else: else:
n = False n = False
@ -246,7 +246,7 @@ def update_ids(year, month=None, day=None, sort=None, expexted=None):
json.dump(films, fd, indent=4, ensure_ascii=False, sort_keys=True) json.dump(films, fd, indent=4, ensure_ascii=False, sort_keys=True)
r = len(films) r = len(films)
if r != expected: if r != expected:
print('%s: got %s, expected %s' % (key, r, expexted)) print('%s: got %s, expected %s' % (key, r, expected))
return r return r
def save_film_counts(film_counts): def save_film_counts(film_counts):

View file

@ -3,6 +3,7 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
import movie.models import movie.models
import movie.imdbids
class Command(BaseCommand): class Command(BaseCommand):
""" """
@ -11,6 +12,12 @@ class Command(BaseCommand):
help = 'load ids from sites that dont support search.' help = 'load ids from sites that dont support search.'
args = '' args = ''
def add_arguments(self, parser):
parser.add_argument('--debug', action='store_true', dest='debug', default=False, help='print debug info')
def handle(self, **options): def handle(self, **options):
timeout = 30*24*60*60 timeout = 30*24*60*60
if options.get('debug'):
movie.imdbids.DEBUG = True
movie.models.get_new_ids(timeout) movie.models.get_new_ids(timeout)