diff --git a/README.md b/README.md index bd46432a..8f7f272d 100644 --- a/README.md +++ b/README.md @@ -366,12 +366,13 @@ Upload medias to your feed. Common arguments: * `path` - Path to source file * `caption` - Text for you post +* `storyUpload` - If True will create a story from image (default: False) * `usertags` - List[Usertag] of mention users (see `Usertag` in [types.py](/instagrapi/types.py)) * `location` - Location (e.g. `Location(name='Test', lat=42.0, lng=42.0)`) | Method | Return | Description | | ------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------------------------- | -| photo_upload(path: Path, caption: str, upload_id: str, usertags: List[Usertag], location: Location) | Media | Upload photo (Support JPG files) | +| photo_upload(path: Path, caption: str, storyUpload:bool , upload_id: str, usertags: List[Usertag], location: Location) | Media | Upload photo (Support JPG files) | | video_upload(path: Path, caption: str, thumbnail: Path, usertags: List[Usertag], location: Location) | Media | Upload video (Support MP4 files) | | igtv_upload(path: Path, title: str, caption: str, thumbnail: Path, usertags: List[Usertag], location: Location) | Media | Upload IGTV (Support MP4 files) | | album_upload(paths: List[Path], caption: str, usertags: List[Usertag], location: Location) | Media | Upload Album (Support JPG and MP4) | @@ -382,6 +383,7 @@ Upload medias to your stories. Common arguments: * `path` - Path to media file * `caption` - Caption for story (now use to fetch mentions) +* `blur` - Fill Story Background with Image Blur (Default: True) * `thumbnail` - Thumbnail instead capture from source file * `mentions` - Tag profiles in story * `locations` - Add locations to story diff --git a/examples/photos/example.jpg b/examples/photos/example.jpg new file mode 100644 index 00000000..46beb547 Binary files /dev/null and b/examples/photos/example.jpg differ diff --git a/examples/photos/example.jpg_STORIES.jpg b/examples/photos/example.jpg_STORIES.jpg new file mode 100644 index 00000000..dd532f99 Binary files /dev/null and b/examples/photos/example.jpg_STORIES.jpg differ diff --git a/examples/photos/upload_photos.py b/examples/photos/upload_photos.py new file mode 100644 index 00000000..6e355840 --- /dev/null +++ b/examples/photos/upload_photos.py @@ -0,0 +1,6 @@ +from instagrapi import Client + +cl = Client() +cl.login("YOUR_LOGIN", "YOUR_PASSWORD") + +cl.photo_upload("example.jpg"," 😀 😃 😄 😁 😆 😅 😂 🤣 ", True) \ No newline at end of file diff --git a/instagrapi/extractors.py b/instagrapi/extractors.py index 8e595cac..fc4cb2a8 100644 --- a/instagrapi/extractors.py +++ b/instagrapi/extractors.py @@ -156,6 +156,30 @@ def extract_location(data): """Extract location info""" if not data: return None + data["pk"] = data.get("id", data.get("pk")) + data["external_id"] = data.get("external_id", data.get("facebook_places_id")) + data["external_id_source"] = data.get( + "external_id_source", data.get("external_source") + ) + + # address_json = data.get("address_json", "{}") + # if isinstance(address_json, str): + # address_json = json.loads(address_json) + # data['address_json'] = address_json + return Location(**data) + + + +def extract_locationV2(data): + """Extract location info""" + if not data: + return None + data=data["place"]["location"] + data["pk"] = data.get("id", data.get("pk")) + try: + data=data["place"]["location"] + except: + pass data["pk"] = data.get("id", data.get("pk", None)) data["external_id"] = data.get("external_id", data.get("facebook_places_id")) data["external_id_source"] = data.get( diff --git a/instagrapi/mixins/location.py b/instagrapi/mixins/location.py index 4de8f692..cc54b6e0 100644 --- a/instagrapi/mixins/location.py +++ b/instagrapi/mixins/location.py @@ -4,7 +4,7 @@ from instagrapi.exceptions import (ClientLoginRequired, ClientNotFoundError, LocationNotFound) -from instagrapi.extractors import extract_location +from instagrapi.extractors import extract_location,extract_locationV2 from instagrapi.types import Location, Media @@ -42,6 +42,98 @@ def location_search(self, lat: float, lng: float) -> List[Location]: venue["lat"] = lat venue["lng"] = lng locations.append(extract_location(venue)) + + print("location list") + print(locations) + print("--end location list") + + return locations + + 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_locationV2(places) + if single_location.pk==pk: + location=single_location + + return location + + 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_locationV2(places)) + + return locations + + def location_search_pk(self, location_pk: int) -> Location: + """ + Get locations using pk + + Parameters + ---------- + pk: int + id + Returns + ------- + Location + An object of Location + """ + result = self.top_search(self.location_info(location_pk).name) + + location = "{}" + for places in result["places"]: + single_location=extract_location(places) + if int(single_location.pk)==location_pk: + location=single_location + break + + return location + + def location_search_name(self, locationName) -> List[Location]: + """ + Get locations using locationName + + 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 def location_complete(self, location: Location) -> Location: @@ -95,14 +187,18 @@ def location_build(self, location: Location) -> str: ------- str """ - if not location: - return "{}" - if not location.external_id and location.lat: - try: - location = self.location_search(location.lat, location.lng)[0] - except IndexError: - pass + if location.pk != None: + location = self.location_search_pk(location.pk) + else: + if not location: + return "{}" + if not location.external_id and location.lat: + try: + location = self.location_search(location.lat, location.lng)[0] + except IndexError: + pass data = { + "pk": location.pk, "name": location.name, "address": location.address, "lat": location.lat, @@ -110,6 +206,7 @@ def location_build(self, location: Location) -> str: "external_source": location.external_id_source, "facebook_places_id": location.external_id, } + return json.dumps(data, separators=(",", ":")) def location_info_a1(self, location_pk: int) -> Location: diff --git a/instagrapi/mixins/photo.py b/instagrapi/mixins/photo.py index 36173260..268af63c 100644 --- a/instagrapi/mixins/photo.py +++ b/instagrapi/mixins/photo.py @@ -163,6 +163,7 @@ def photo_upload( self, path: Path, caption: str, + storyUpload:bool=False, upload_id: str = "", usertags: List[Usertag] = [], location: Location = None, @@ -198,6 +199,8 @@ def photo_upload( ): media = self.last_json.get("media") self.expose() + if storyUpload: + self.photo_upload_to_story(path,caption) return extract_media_v1(media) raise PhotoConfigureError( response=self.last_response, **self.last_json diff --git a/instagrapi/mixins/private.py b/instagrapi/mixins/private.py index bbb7a5e3..8858d6d2 100644 --- a/instagrapi/mixins/private.py +++ b/instagrapi/mixins/private.py @@ -181,9 +181,12 @@ def _send_private_request( if self.user_id and login: raise Exception(f"User already login ({self.user_id})") try: - if not endpoint.startswith('/'): - endpoint = f"/v1/{endpoint}" - api_url = f"https://{config.API_DOMAIN}/api{endpoint}" + if "topsearch" in endpoint: + api_url= endpoint + else: + if not endpoint.startswith('/'): + endpoint = f"/v1/{endpoint}" + api_url = f"https://{config.API_DOMAIN}/api{endpoint}" if data: # POST # Client.direct_answer raw dict # data = json.dumps(data) diff --git a/instagrapi/mixins/public.py b/instagrapi/mixins/public.py index e88092eb..80765cf7 100644 --- a/instagrapi/mixins/public.py +++ b/instagrapi/mixins/public.py @@ -234,7 +234,7 @@ def top_search(self, query): "rank_token": 0.7763938004511706, "include_reel": "true", } - response = self.public_request(url, params=params, return_json=True) + response = self.private_request(url, params=params) return response