Chrunos commited on
Commit
bc69dda
·
verified ·
1 Parent(s): d5fe959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
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
- try:
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
- # Fetch post by shortcode
90
- post = instaloader.Post.from_shortcode(L.context, shortcode)
91
- logger.info(f"Fetched post: {post}")
92
- break
93
-
94
- except instaloader.exceptions.ConnectionException as e:
95
- logger.error(f"Connection error (attempt {attempt + 1}): {e}")
96
- if attempt == max_retries - 1:
97
- raise HTTPException(status_code=500, detail="Failed to connect to Instagram after multiple attempts")
98
- time.sleep(retry_delay)
99
- retry_delay *= 2 # Exponential backoff
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")