Beispiel #1
0
    def get_checkins_info(self, urls):
        """Return info from a batch of `urls`"""
        id_and_sig = self.expand_urls(urls)
        raw_checkins = self.query_foursquare(id_and_sig)

        res = []
        for cid, sig in id_and_sig:
            if not cid:
                res.append(None)
                continue
            try:
                raw_checkin = raw_checkins.next()
            except foursquare.ServerError as oops:
                logging.exception('error in getting next checkin')
                if 'status' in str(oops):
                    waiting_time = self.failures.fail()
                    if self.failures.recent_failures >= 5:
                        raise FoursquareDown
                    msg = 'Will wait for {:.0f} seconds'.format(waiting_time)
                    logging.info(msg)
            if isinstance(raw_checkin, foursquare.FoursquareException):
                msg = 'Weird id: {}?s={}\n{}'.format(cid, sig,
                                                     str(raw_checkin))
                logging.warn(msg)
                res.append(None)
            else:
                parsed = th.parse_json_checkin(raw_checkin)
                checkin_info = None
                if parsed:
                    checkin_info = (cid + '?s=' + sig, ) + parsed
                res.append(checkin_info)
        return res
Beispiel #2
0
    def get_checkins_info(self, urls):
        """Return info from a batch of `urls`"""
        id_and_sig = self.expand_urls(urls)
        raw_checkins = self.query_foursquare(id_and_sig)

        res = []
        for cid, sig in id_and_sig:
            if not cid:
                res.append(None)
                continue
            try:
                raw_checkin = raw_checkins.next()
            except foursquare.ServerError as oops:
                logging.exception('error in getting next checkin')
                if 'status' in str(oops):
                    waiting_time = self.failures.fail()
                    if self.failures.recent_failures >= 5:
                        raise FoursquareDown
                    msg = 'Will wait for {:.0f} seconds'.format(waiting_time)
                    logging.info(msg)
            if isinstance(raw_checkin, foursquare.FoursquareException):
                msg = 'Weird id: {}?s={}\n{}'.format(cid, sig,
                                                     str(raw_checkin))
                logging.warn(msg)
                res.append(None)
            else:
                parsed = th.parse_json_checkin(raw_checkin)
                checkin_info = None
                if parsed:
                    checkin_info = (cid + '?s=' + sig, ) + parsed
                res.append(checkin_info)
        return res
Beispiel #3
0
 def get_checkin_info(self, curl_object):
     """Analyze the answer from `curl_object` to return checkin id, user id,
     venue id and checkin local time."""
     if curl_object.getinfo(vc.pycurl.HTTP_CODE) != 200:
         return None
     url = curl_object.getinfo(vc.pycurl.EFFECTIVE_URL)
     id_ = url.split('/')[-1]
     match = self.checkin_url.match(id_)
     if not match:
         return None
     cid, sig = match.group(1, 2)
     tree = etree.fromstring(curl_object.buf.getvalue(), PARSER)
     script = tree.xpath(XPATH_GET_SCRIPT)
     if not script:
         return None
     # the HTML contains a script that in turn has a checkin JSON
     # object between these two indices.
     checkin = th.parse_json_checkin(script[0].text[76:-118], url)
     if not checkin:
         return None
     uid, vid, time = checkin
     return cid + '?s=' + sig, uid, vid, time
Beispiel #4
0
 def get_checkin_info(self, curl_object):
     """Analyze the answer from `curl_object` to return checkin id, user id,
     venue id and checkin local time."""
     if curl_object.getinfo(vc.pycurl.HTTP_CODE) != 200:
         return None
     url = curl_object.getinfo(vc.pycurl.EFFECTIVE_URL)
     id_ = url.split('/')[-1]
     match = self.checkin_url.match(id_)
     if not match:
         return None
     cid, sig = match.group(1, 2)
     tree = etree.fromstring(curl_object.buf.getvalue(), PARSER)
     script = tree.xpath(XPATH_GET_SCRIPT)
     if not script:
         return None
     # the HTML contains a script that in turn has a checkin JSON
     # object between these two indices.
     checkin = th.parse_json_checkin(script[0].text[76:-118], url)
     if not checkin:
         return None
     uid, vid, time = checkin
     return cid + '?s=' + sig, uid, vid, time