示例#1
0
 def __call__(self, **params):
     params['method'] = self.method
     params['api_key'] = self.api_key
     params['format'] = 'json'
     params['nojsoncallback'] = '1'
     url = "http://flickr.com/services/rest/?" + urllib.urlencode(params)
     json = utils.getjson(url)
     if json.get("stat", "") == "fail":
         raise FlickrError(json["code"], json["message"])
     return json
示例#2
0
 def __call__(self, **params):
     params['method'] = self.method
     params['api_key'] = self.api_key
     params['format'] = 'json'
     params['nojsoncallback'] = '1'
     url = "http://flickr.com/services/rest/?" + urllib.urlencode(params)
     json = utils.getjson(url)
     if json.get("stat", "") == "fail":
         raise FlickrError(json["code"], json["message"])
     return json
示例#3
0
文件: flickr.py 项目: davej/jellyroll
 def __call__(self, **params):
     params["method"] = self.method
     params["api_key"] = self.api_key
     params["format"] = "json"
     params["nojsoncallback"] = "1"
     url = "http://flickr.com/services/rest/?" + urllib.urlencode(params)
     json = utils.getjson(url)
     if json.get("stat", "") == "fail":
         raise FlickrError(json["code"], json["message"])
     return json
示例#4
0
def _update_location(user_id, since):
    json = utils.getjson('http://www.google.com/latitude/apps/badge/api?user=%s&type=json' % user_id)
    feature = json['features'][0]
    
    lat, lng = map(str, feature['geometry']['coordinates'])
    name = feature['properties']['reverseGeocode']
    timestamp = datetime.datetime.fromtimestamp(feature['properties']['timeStamp'])
    if timestamp > since:
        log.debug("New location: %s", name)
        loc = Location(latitude=lat, longitude=lng, name=name)
        return Item.objects.create_or_update(
            instance = loc,
            timestamp = timestamp,
            source = __name__,
            source_id = str(feature['properties']['timeStamp']),
        )
示例#5
0
    def _make_request(self, api_endpoint):
        params = {
            'oauth_token': self.oauth_token,
            'oauth_consumer_key': settings.NETFLIX_CONSUMER_KEY,
            'oauth_nonce': oauth.generate_nonce(),
            'oauth_timestamp': int(time.time()),
            'output': 'json',
            'max_results': '20' # up to 100 legally, but will give back more (200?)
        }
        if self.updated_min:
            params['updated_min'] = self.updated_min
        consumer = oauth.Consumer(settings.NETFLIX_CONSUMER_KEY, settings.NETFLIX_CONSUMER_SECRET)
        token = oauth.Token(key=self.oauth_token, secret=self.oauth_token_secret)
        req = oauth.Request(method="GET", url=api_endpoint, parameters=params)
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        req.sign_request(signature_method, consumer, token)

        url = req.to_url()
        json = utils.getjson(url)
        if json.has_key('status'):
            raise NetflixError(json['status']['status_code'], json['status']['message'])
        return json
示例#6
0
def update():
    page = 0
    done = False
    while not done:
        log.debug("Fetching page %s", page)
        resp = utils.getjson(POWNCE_URL % (settings.POWNCE_USERNAME, "messages", page))
        if resp.has_key("error") and resp["error"]["status_code"] == 404:
            log.debug("Ran out of results; finishing.")
            break

        for message in resp["notes"]:
            if _item_already_exists(message["id"]):
                log.debug("Found note that already exists (%s); finishing.", message["id"])
                done = True
                break
            _handle_message(
                id=message["id"],
                timestamp=datetime.datetime.fromtimestamp(message["timestamp"]),
                message=message["body"],
            )

        page += 1