#Instagram

1 messages · Page 1 of 1 (latest)

rotund sequoia
#

Hello,
I have a problem with my Pycord Bot.
I have always posted my latest Instagram posts to my Discord server.
I have always done this through the feed.

    def get_instagram_html(self, username):
        headers = {
            "Host": "www.instagram.com",
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
        }
        html = requests.get("https://www.instagram.com/" +
                            username + "/feed/", headers=headers)
        return html```
But this does not work anymore. Does anyone have an actual solution for this?
rotund sequoia
#

So the feed can not be saved as html and processed further and I do not know why

#

I use this:

import requests


class Instagram_Photos():
    def __init__(self, username):
        self.username = username
        self.html = self.get_instagram_html(self.username)
        self.fullname = self.get_user_fullname(self.html)
        self.totalphotos = self.get_total_photos(self.html)
        self.lastimgid = self.get_last_publication_url(self.html)
        self.lastimage_url = self.get_last_thumb_url(self.html)
        self.description = self.get_description_photo(self.html)

    def get_user_fullname(self, html):
        return html.json()["graphql"]["user"]["full_name"]

    def get_total_photos(self, html):
        return int(html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["count"])

    def get_last_publication_url(self, html):
        return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["shortcode"]

    def get_last_photo_url(self, html):
        return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["display_url"]

    def get_last_thumb_url(self, html):
        return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["thumbnail_src"]

    def get_description_photo(self, html):
        return \
        html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["edge_media_to_caption"][
            "edges"][0]["node"]["text"]

    def get_instagram_html(self, username):
        headers = {
            "Host": "www.instagram.com",
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"
        }
        html = requests.get("https://www.instagram.com/" +
                            username + "/feed/", headers=headers)
        return html```
#

And with this part, the post is actually supposed to be posted in the channel:

@tasks.loop(seconds=120)
async def post_instagram_photo():
    channelid = INSTA_CHANNEL_ID
    channel = await client.fetch_channel(channelid)

    iclient = Instagram_Photos(IG_USERNAME)

    with open("instagram.json", "r") as f:
        js = json.load(f)

    last_photo_id = js["last_photo_id"]

    if last_photo_id == iclient.lastimgid:
        pass
    else:
        embed = discord.Embed(description=iclient.description, color=15467852)
        embed.url = f"https://www.instagram.com/p/{iclient.lastimgid}"
        embed.set_author(name=f"CryptoTradeDE (@{iclient.username})", url=INSTAGRAM_URL, icon_url=INSTAGRAM_PROFIL_IMAGE_URL)
        embed.set_image(url=iclient.lastimage_url)
        embed.set_footer(icon_url=INSTAGRAM_LOGO, text="Instagram")
        embed.timestamp = discord.utils.utcnow()

        await channel.send(embed=embed)

        js["last_photo_id"] = iclient.lastimgid

        with open("instagram.json", "w") as f:
            json.dump(js, f)```
#

But in the upper part the data are not read out accordingly so that the possibility exists to post these at all

rotund sequoia