Update app.py
Browse files
app.py
CHANGED
@@ -72,31 +72,32 @@ async def download_post(request: PostRequest):
|
|
72 |
raise HTTPException(status_code=400, detail=str(e))
|
73 |
|
74 |
L = instaloader.Instaloader()
|
75 |
-
|
76 |
-
# Login to Instagram
|
77 |
-
L.login(INSTAGRAM_USERNAME, INSTAGRAM_PASSWORD)
|
78 |
-
logger.info("Successfully logged in to Instagram")
|
79 |
-
except instaloader.exceptions.InstaloaderException as e:
|
80 |
-
logger.error(f"Login error: {e}")
|
81 |
-
raise HTTPException(status_code=500, detail="Error logging in to Instagram")
|
82 |
-
|
83 |
-
# Configure retry parameters
|
84 |
-
max_retries = 3
|
85 |
-
retry_delay = random.uniform(30, 60)
|
86 |
-
|
87 |
-
for attempt in range(max_retries):
|
88 |
try:
|
89 |
-
#
|
90 |
-
|
91 |
-
logger.info(
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
except instaloader.exceptions.InvalidArgumentException:
|
102 |
logger.error(f"Post not found for shortcode: {shortcode}")
|
|
|
72 |
raise HTTPException(status_code=400, detail=str(e))
|
73 |
|
74 |
L = instaloader.Instaloader()
|
75 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
try:
|
77 |
+
# Login to Instagram
|
78 |
+
L.login(INSTAGRAM_USERNAME, INSTAGRAM_PASSWORD)
|
79 |
+
logger.info("Successfully logged in to Instagram")
|
80 |
+
except instaloader.exceptions.InstaloaderException as e:
|
81 |
+
logger.error(f"Login error: {e}")
|
82 |
+
raise HTTPException(status_code=500, detail="Error logging in to Instagram")
|
83 |
+
|
84 |
+
# Configure retry parameters
|
85 |
+
max_retries = 3
|
86 |
+
retry_delay = random.uniform(30, 60)
|
87 |
+
|
88 |
+
for attempt in range(max_retries):
|
89 |
+
try:
|
90 |
+
# Fetch post by shortcode
|
91 |
+
post = instaloader.Post.from_shortcode(L.context, shortcode)
|
92 |
+
logger.info(f"Fetched post: {post}")
|
93 |
+
break
|
94 |
+
|
95 |
+
except instaloader.exceptions.ConnectionException as e:
|
96 |
+
logger.error(f"Connection error (attempt {attempt + 1}): {e}")
|
97 |
+
if attempt == max_retries - 1:
|
98 |
+
raise HTTPException(status_code=500, detail="Failed to connect to Instagram after multiple attempts")
|
99 |
+
time.sleep(retry_delay)
|
100 |
+
retry_delay *= 2 # Exponential backoff
|
101 |
|
102 |
except instaloader.exceptions.InvalidArgumentException:
|
103 |
logger.error(f"Post not found for shortcode: {shortcode}")
|