示例#1
0
文件: flickr.py 项目: davej/Ojax-old
def update():
    flickr = FlickrClient(settings.FLICKR_API_KEY)
    
    # Preload the list of licenses
    licenses = licenses = flickr.photos.licenses.getInfo()
    licenses = dict((l["id"], smart_unicode(l["url"])) for l in licenses["licenses"]["license"])
    
    # Handle update by pages until we see photos we've already handled
    last_update_date = Item.objects.get_last_update_of_model(Photo)
    page = 1
    while True:
        log.debug("Fetching page %s of photos", page)
        resp = flickr.people.getPublicPhotos(user_id=settings.FLICKR_USER_ID, extras="license,date_taken", per_page="500", page=str(page))
        photos = resp["photos"]
        if page > photos["pages"]:
            log.debug("Ran out of photos; stopping.")
            break
            
        for photodict in photos["photo"]:
            timestamp = utils.parsedate(str(photodict["datetaken"]))
            if timestamp < last_update_date:
                log.debug("Hit an old photo (taken %s; last update was %s); stopping.", timestamp, last_update_date)
                break
            
            photo_id = utils.safeint(photodict["id"])
            license = licenses[photodict["license"]]
            secret = smart_unicode(photodict["secret"])
            server = smart_unicode(photodict["server"])
            _handle_photo(flickr, photo_id, secret, license, timestamp)
            
        page += 1
示例#2
0
def update():
    d = feedparser.parse("http://feeds.delicious.com/rss/bittered/%s" % \
     "ojax")

    # Check to see if we need an update
    last_update_date = Item.objects.get_last_update_of_model(Bookmark)
    try:
        last_post_date = utils.parsedate(d.entries[0].updated)
        if last_post_date <= last_update_date:
            log.info("Skipping update: last update date: %s; last post date: %s", \
             last_update_date, last_post_date)
            return
    except:
        pass

            
    for entry in d.entries:
        dt = utils.parsedate(entry.updated)
        if dt > last_update_date:
            _prepare_bookmark(entry, dt)