Fred808 commited on
Commit
ab8a00c
·
verified ·
1 Parent(s): 618571d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,7 +1,8 @@
1
  from fastapi import FastAPI, HTTPException
2
  import instaloader
3
  from pydantic import BaseModel
4
- from typing import List, Dict
 
5
 
6
  app = FastAPI()
7
 
@@ -13,10 +14,13 @@ class PostResponse(BaseModel):
13
  posted_on: str
14
  image_url: str
15
 
 
 
 
16
  @app.get("/fetch-posts", response_model=List[PostResponse])
17
  async def fetch_instagram_posts(username: str, max_posts: int = 10):
18
  """
19
- Fetch Instagram posts from a public profile.
20
 
21
  Args:
22
  username (str): The username of the Instagram profile.
@@ -25,8 +29,9 @@ async def fetch_instagram_posts(username: str, max_posts: int = 10):
25
  Returns:
26
  List[PostResponse]: A list of posts with caption, likes, comments, posted_on, and image_url.
27
  """
28
- # Initialize Instaloader
29
  L = instaloader.Instaloader()
 
30
 
31
  try:
32
  # Load the profile
@@ -68,4 +73,4 @@ async def fetch_instagram_posts(username: str, max_posts: int = 10):
68
  # Run the FastAPI app
69
  if __name__ == "__main__":
70
  import uvicorn
71
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
  from fastapi import FastAPI, HTTPException
2
  import instaloader
3
  from pydantic import BaseModel
4
+ from typing import List
5
+ import os
6
 
7
  app = FastAPI()
8
 
 
14
  posted_on: str
15
  image_url: str
16
 
17
+ # Define proxy settings (replace with your proxy details)
18
+ PROXY_URL = "http://p.webshare.io:5157:kknqfmqe:0wyvognccou8"
19
+
20
  @app.get("/fetch-posts", response_model=List[PostResponse])
21
  async def fetch_instagram_posts(username: str, max_posts: int = 10):
22
  """
23
+ Fetch Instagram posts from a public profile using a proxy.
24
 
25
  Args:
26
  username (str): The username of the Instagram profile.
 
29
  Returns:
30
  List[PostResponse]: A list of posts with caption, likes, comments, posted_on, and image_url.
31
  """
32
+ # Initialize Instaloader with proxy configuration
33
  L = instaloader.Instaloader()
34
+ L.context.proxy = PROXY_URL
35
 
36
  try:
37
  # Load the profile
 
73
  # Run the FastAPI app
74
  if __name__ == "__main__":
75
  import uvicorn
76
+ uvicorn.run(app, host="0.0.0.0", port=8000)