Exemplo n.º 1
0
def source(request, source=''):
    s = db.get_source(source)
    if s is None:
        return _404_response()
    start, end, limit = _parse_params(request)
    articles = db.list_articles_by_source(source, start=start, end=end, limit=limit)
    s['articles'] = articles
    return json_response(s)
Exemplo n.º 2
0
def source(request):
    s = _get(request, 's')
    if not s:
        return HttpResponseRedirect('/')
    articles = db.list_articles_by_source(s)
    if not articles:
        return HttpResponseRedirect('/')
    for article in articles:
        article['url'] = urllib.unquote(article['url'])
    source = db.get_source(s)
    return render_to_response('source.html', dict(articles=articles,
                                                  source=source))
Exemplo n.º 3
0
import time

def fix_0A(a):
    if '0A' in a['url']:
        print a['url']
        a['url'] = a['url'].replace('0A', '0')
        return True
    return False

def fetch_text(a):
    if a['cached']:
        return False
    time.sleep(0.2)
    txt = lp.fetch_text(urllib.unquote(a['url']))
    if txt:
        print a['url_date'], a['title'], a['url']
        a['cached'] = txt
        return True
    return False


source = u'自由時報'
articles = db.list_articles_by_source(source, addition_cols=['cached'])
fixed = 0
for a in articles:
    if any((fix_0A(a), fetch_text(a))):
        #print 'fixed', a
        db.ensure_article_exists(a, overwrite=True)
        fixed += 1
print 'total: %s, fixed: %s' % (len(articles), fixed)