def create_if_doesnt_exist(url): try: Domain.objects.get(url=url) except Domain.DoesNotExist: site_data = sites[url] site_data['url'] = url site = Domain(**site_data) site.save()
from livetime.models import Domain try: Domain.objects.get(url='bbc.co.uk') except Domain.DoesNotExist: bbc = Domain(url='bbc.co.uk', title_selector="h1.story-header", date_selector="span.date", date_fmt="%d %B %Y") bbc.save() try: Domain.objects.get(url='guardian.co.uk') except Domain.DoesNotExist: guardian = Domain(url='guardian.co.uk', title_selector='#main-article-info h1', date_selector='.publication time', date_fmt="%A %d %B %Y %H.%M %Z") guardian.save() sites = {'bbc.co.uk':{'title_selector':'h1 .story-header', 'date_selector':'meta[property=OriginalPublicationDate]&content', 'date_fmt':"%Y/%m/%d %H:%M:%S"}, 'guardian.co.uk': {'title_selector':'title', 'date_selector':'meta[property=article:published_time]&content', 'date_fmt':"%Y-%m-%dT%H:%M:%S%z"}, 'huffingtonpost.com': {'title_selector':'meta[property=og:title]&content', 'date_selector':'meta[name=publish_date]&content',
from livetime.models import Domain try: Domain.objects.get(url='bbc.co.uk') except Domain.DoesNotExist: bbc = Domain(url='bbc.co.uk', title_selector="h1.story-header", date_selector="span.date", date_fmt="%d %B %Y") bbc.save() try: Domain.objects.get(url='guardian.co.uk') except Domain.DoesNotExist: guardian = Domain(url='guardian.co.uk', title_selector='#main-article-info h1', date_selector='.publication time', date_fmt="%A %d %B %Y %H.%M %Z") guardian.save() sites = { 'bbc.co.uk': { 'title_selector': 'h1 .story-header', 'date_selector': 'meta[property=OriginalPublicationDate]&content', 'date_fmt': "%Y/%m/%d %H:%M:%S" }, 'guardian.co.uk': { 'title_selector': 'title', 'date_selector': 'meta[property=article:published_time]&content', 'date_fmt': "%Y-%m-%dT%H:%M:%S%z"