コード例 #1
0
    def media_info_gql(self, media_pk: int) -> Media:
        """
        Get Media from PK

        Parameters
        ----------
        media_pk: int
            Unique identifier of the media

        Returns
        -------
        Media
            An object of Media type
        """
        media_pk = self.media_pk(media_pk)
        shortcode = InstagramIdCodec.encode(media_pk)
        """Use Client.media_info
        """
        variables = {
            "shortcode": shortcode,
            "child_comment_count": 3,
            "fetch_comment_count": 40,
            "parent_comment_count": 24,
            "has_threaded_comments": False,
        }
        data = self.public_graphql_request(
            variables, query_hash="477b65a610463740ccdb83135b2014db")
        if not data.get("shortcode_media"):
            raise MediaNotFound(media_pk=media_pk, **data)
        if data["shortcode_media"]["location"]:
            data["shortcode_media"]["location"] = self.location_complete(
                extract_location(data["shortcode_media"]["location"])).dict()
        return extract_media_gql(data["shortcode_media"])
コード例 #2
0
    def location_search(self, lat: float, lng: float) -> List[Location]:
        """
        Get locations using lat and long

        Parameters
        ----------
        lat: float
            Latitude you want to search for
        lng: float
            Longitude you want to search for

        Returns
        -------
        List[Location]
            List of objects of Location
        """
        params = {
            'latitude': lat,
            'longitude': lng,
            # rankToken=c544eea5-726b-4091-a916-a71a35a76474 - self.uuid?
            # fb_access_token=EAABwzLixnjYBABK2YBFkT...pKrjju4cijEGYtcbIyCSJ0j4ZD
        }
        result = self.private_request("location_search/", params=params)
        locations = []
        for venue in result['venues']:
            if 'lat' not in venue:
                venue['lat'] = lat
                venue['lng'] = lng
            locations.append(extract_location(venue))
        return locations
コード例 #3
0
    def location_info_a1(self, location_pk: int) -> Location:
        """
        Get a location using location pk

        Parameters
        ----------
        location_pk: int
            Unique identifier for a location

        Returns
        -------
        Location
            An object of Location
        """
        data = self.public_a1_request(f"/explore/locations/{location_pk}/")
        return extract_location(data['location'])
コード例 #4
0
    def location_info_v1(self, location_pk: int) -> Location:
        """
        Get a location using location pk

        Parameters
        ----------
        location_pk: int
            Unique identifier for a location

        Returns
        -------
        Location
            An object of Location
        """
        result = self.private_request(
            f"locations/{location_pk}/location_info/")
        return extract_location(result)
コード例 #5
0
ファイル: fbsearch.py プロジェクト: adw0rd/instagrapi
 def fbsearch_places(self,
                     query: str,
                     lat: float = 40.74,
                     lng: float = -73.94) -> List[Location]:
     params = {
         'search_surface': 'places_search_page',
         'timezone_offset': self.timezone_offset,
         'lat': lat,
         'lng': lng,
         'count': 30,
         'query': query,
     }
     result = self.private_request("fbsearch/places/", params=params)
     locations = []
     for item in result['items']:
         locations.append(extract_location(item['location']))
     return locations
コード例 #6
0
    def location_search_name(self, LocationName: str) -> List[Location]:
        """
        Get locations using name

        Parameters
        ----------
        LocationName: string
                    LocationName
        Returns
        -------
        List[Location]
            List of objects of Location
        """
        result = self.top_search(LocationName)
        locations = []
        for places in result["places"]:
            locations.append(extract_location(places))

        return locations
コード例 #7
0
    def location_search(self, lat: float, lng: float) -> List[Location]:
        """
        Get locations using lat and long

        Parameters
        ----------
        lat: float
            Latitude you want to search for
        lng: float
            Longitude you want to search for

        Returns
        -------
        List[Location]
            List of objects of Location
        """
        params = {
            "latitude": lat,
            "longitude": lng,
            # rankToken=c544eea5-726b-4091-a916-a71a35a76474 - self.uuid?
            # fb_access_token=EAABwzLixnjYBABK2YBFkT...pKrjju4cijEGYtcbIyCSJ0j4ZD
        }
        #Calculate approximate radius of earth in km
        R = 6373.0
        lat1 = radians(lat)
        lon1 = radians(lng)
        result = self.private_request("location_search/", params=params)
        locations = []
        for venue in result["venues"]:
            if "lat" in venue:
                lat2 = radians(venue["lat"])
                lon2 = radians(venue["lng"])
                dlon = lon2 - lon1
                dlat = lat2 - lat1
                a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
                c = 2 * atan2(sqrt(a), sqrt(1 - a))
                precision = R * c
                #return approximate of two coordinates in km
                if precision < 1:
                    loc = extract_location(venue)
                    loc.precision = precision
                    locations.append(loc)
        return sorted(locations, key=lambda k: k.precision)
コード例 #8
0
    def location_info_a1(self, location_pk: int) -> Location:
        """
        Get a location using location pk

        Parameters
        ----------
        location_pk: int
            Unique identifier for a location

        Returns
        -------
        Location
            An object of Location
        """
        try:
            data = self.public_a1_request(f"/explore/locations/{location_pk}/")
            if not data.get("location"):
                raise LocationNotFound(location_pk=location_pk, **data)
            return extract_location(data["location"])
        except ClientNotFoundError:
            raise LocationNotFound(location_pk=location_pk)
コード例 #9
0
    def location_search_pk(self, pk: int) -> Location:
        """
        Get locations using pk

        Parameters
        ----------
        pk: int
            id
        Returns
        -------
        Location
            An object of Location
        """
        result = self.top_search(self.location_info(pk).name)

        location = "{}"
        for places in result["places"]:
            single_location = extract_location(places)
            if single_location.pk == pk:
                location = single_location

        return location