コード例 #1
0
ファイル: urls.py プロジェクト: Timewire/timewire
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()
コード例 #2
0
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()
コード例 #3
0
ファイル: urls.py プロジェクト: Timewire/timewire
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',
コード例 #4
0
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"