Пример #1
0
def fetch_shows(artist, next_page=1):
    url = SHOWS_URL.format(artist.id(), next_page)
    result = urlfetch.fetch(url)
    if result.status_code != 200:
        return
    data =  json.loads(result.content[9:-1])
    for doc in data['response']['docs']:
        show = ShowRecording(artist=artist,
                title=doc.get('title',''), 
                identifier=doc.get('identifier',''),
                description=doc.get('description',''), 
                source=doc.get('source',''), 
                downloads=int(doc.get('downloads',0)), 
                coverage=doc.get('coverage',[]),
                subject=doc.get('subject',[]),
                date=datetime.datetime.strptime(doc.get('date', '1500-01-01T00:00:00Z'), '%Y-%m-%dT%H:%M:%SZ'))
        show.put_async()
    if next_page==1:
        count = int(data['response']['numFound'])
        if count > 50:
            for page in range(2, (count / 50)+1):
                deferred.defer(fetch_shows, artist, next_page=page)
Пример #2
0
def resave():
    for show in ShowRecording.query().iter():
        show.put_async()