最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

server - Python Telegram bot - Stack Overflow

matteradmin3PV0评论

I have some problems with server.

import time
import instaloader
import requests
from io import BytesIO

def instagram_downloander(url, content_type):
    print(f"Content Type: {content_type}")

    try:
        ig = instaloader.Instaloader()

        shortcode = url.split('/')[-2]
        post = instaloader.Post.from_shortcode(ig.context, shortcode)

        for _ in range(3):  
            try:
                post = instaloader.Post.from_shortcode(ig.context, shortcode)
                if post.is_video:
                    video_url = post.video_url
                    response = requests.get(video_url)
                    if response.status_code == 200:
                        return BytesIO(response.content), 'video'
                else:
                    image_url = post.url
                    response = requests.get(image_url)
                    if response.status_code == 200:
                        return BytesIO(response.content), 'image'
            except instaloader.exceptions.TooManyRequestsException:
                print("Rate limit reached. Retrying after delay...")
                time.sleep(600) 
            except Exception as e:
                print(f"Retry failed: {e}")
        print("Unable to download the post. Please try later.")
        return None, None

    except instaloader.exceptions.BadResponseException as e:
        print(f"An error occurred while fetching post metadata: {e}")
        return None, None
    except Exception as e:
        print(f"Unexpected error: {e}")
        time.sleep(10)  
        return instagram_downloander(url, content_type) 

This is my insta.py file and

elif user_state.get(user_id) == 'instagram_post':
        url = update.message.text
        content_type = 'post'
        await update.message.reply_text("Please wait 1 minute for loading...")
        
        media, media_type = instagram_downloander(url, content_type)

        if media and media_type:
            if media_type == 'video':
                await update.message.reply_video(video=media, filename='instagram_video.mp4')
            elif media_type == 'image':
                await update.message.reply_photo(photo=media, filename='instagram_image.jpg')
            else:
                await update.message.reply_text("Unsupported media type.")
                # Credit.deduct_credits(user_id, 1)
            await update.message.reply_text(f"

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far