コード例 #1
0
ファイル: sync.py プロジェクト: Volshebnyi/pasty
 def parse_entry(self, entry):
     p = Pasty()
     p.text = self.strip(entry['summary_detail']['value'])
     p.date = self.to_date(entry['published_parsed'])
     if not p.date:
         p.date = self.source.sync_date
     p.source = self.source.url
     return p
コード例 #2
0
ファイル: parsing.py プロジェクト: soider/pasty
 def parse_entry(self, entry):
     text = entry.find(class_='Text').text.replace('\r\n', '<br/>')
     if len(text) > self.MAX_LENGTH:
         return None
     pasty = Pasty()
     pasty.text = text
     pasty.date = to_date(entry.find(class_='date').text)
     pasty.published = True
     pasty.source = self.source.url
     return pasty
コード例 #3
0
ファイル: parsing.py プロジェクト: soider/pasty
 def parse_entry(self, entry):
     text = self.process_text(entry['summary_detail']['value'])
     if len(text) > self.MAX_LENGTH or \
             not remove_html_tags(text):
         return None
     pasty = Pasty()
     pasty.text = text
     pasty.date = to_date(entry['published_parsed']) or self.last_update
     pasty.published = True
     pasty.source = self.source.url
     return pasty
コード例 #4
0
ファイル: sync.py プロジェクト: Volshebnyi/pasty
    def parse_entry(self, entry):
        # fake sync_date to remove duplicates
        text, date = entry
        p = Pasty()
        p.text = self.strip(text)

        # set latest time possible for proper sync
        date = datetime.strptime(date, '%d.%m.%Y')
        date = date.replace(hour=23, minute=59, second=59)
        p.date = date

        p.source = self.source.url
        return p
コード例 #5
0
ファイル: sync.py プロジェクト: dantyan/pasty
def sync_rss_source(source):

    entries = []

    if source.parser() in globals():
        entries = globals()[source.parser()](source)
    else:
        entries = default_parser(source)

    for entry in entries:
        if not Pasty.objects.filter(unique_key=entry.get('id')):
            print(entry.get('id'))
            p = Pasty(text=entry.get('text'), date=entry.get('date'), source=entry.get('source'), unique_key=entry.get('id'))
            p.save()
コード例 #6
0
ファイル: views.py プロジェクト: Tyrael1989/pasty
def one(request):
    p = Pasty.rnd()
    if p:
        context = {'text': p.text, 'source': p.source, 'title': p.source_title()}
        return render(request, 'core/pasty.html', context)
    else:
        return HttpResponse(u'<div class="box pasty">Нету пирожков :-(</div>')
コード例 #7
0
ファイル: views.py プロジェクト: soider/pasty
def one(request):
    """Returns one pastry, used from javascript for page updates"""
    p = Pasty.rnd()
    if p:
        context = {'text': p.text, 'source': p.source, 'title': p.source_title()}
        return render(request, 'core/pasty.html', context)
    else:
        return HttpResponse(u'<div class="box pasty">Нету пирожков :-(</div>')
コード例 #8
0
def one(request):
    p = Pasty.rnd()
    if p:
        context = {
            'text': p.text,
            'source': p.source,
            'title': p.source_title()
        }
        return render(request, 'core/pasty.html', context)
    else:
        return HttpResponse(u'<div class="box pasty">Нету пирожков :-(</div>')
コード例 #9
0
def stishkipirozhki_ru(sync_date, source, entry):
    p = Pasty()
    p.text = strip(entry['content'][0]['value'])
    p.date = to_date(entry['published_parsed'])
    if not p.date: p.date = sync_date
    p.source = source.url
    return p
コード例 #10
0
def pirozhki_ru_livejournal_com(sync_date, source, entry):
    p = Pasty()
    p.text = strip(entry['summary_detail']['value'])
    p.date = to_date(entry['published_parsed'])
    if not p.date: p.date = sync_date
    p.source = source.url
    if len(p.text) > 255:
        return None
    return p
コード例 #11
0
ファイル: sync.py プロジェクト: Volshebnyi/pasty
    def parse_entry(self, entry):
        p = Pasty()
        p.text = self.strip(entry['summary_detail']['value'])
        p.votes = int(entry['lj_reply-count'])
        p.date = self.to_date(entry['published_parsed'])
        if not p.date:
            p.date = self.source.sync_date
        p.source = self.source.url

        if len(p.text) > 255:
            return None
        return p