Update app.py
Browse files
app.py
CHANGED
@@ -55,7 +55,7 @@ async def rate_limited_api_call(session: ClientSession, bucket: TokenBucket, url
|
|
55 |
for attempt in range(max_retries):
|
56 |
await bucket.wait_for_token()
|
57 |
|
58 |
-
# random delay
|
59 |
await asyncio.sleep(random.uniform(0.1, 0.5))
|
60 |
|
61 |
try:
|
@@ -64,7 +64,7 @@ async def rate_limited_api_call(session: ClientSession, bucket: TokenBucket, url
|
|
64 |
response.raise_for_status()
|
65 |
return await response.json()
|
66 |
elif method == 'POST':
|
67 |
-
async with session.post(url, headers=headers, json=data) as response:
|
68 |
response.raise_for_status()
|
69 |
return await response.json()
|
70 |
except aiohttp.ClientResponseError as e:
|
@@ -135,15 +135,17 @@ async def scrape_facebook_profile(session: ClientSession, bucket: TokenBucket, u
|
|
135 |
logging.info(f"Facebook API Endpoint: {api_endpoint}")
|
136 |
|
137 |
headers = {
|
138 |
-
'Authorization': f'Bearer {api_key}'
|
139 |
-
'Content-Type': 'application/json'
|
140 |
-
}
|
141 |
-
data = {
|
142 |
-
"profile_url": url.strip()
|
143 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
try:
|
146 |
-
result = await rate_limited_api_call(session, bucket, api_endpoint, headers,
|
147 |
|
148 |
if 'error' not in result:
|
149 |
return {
|
|
|
55 |
for attempt in range(max_retries):
|
56 |
await bucket.wait_for_token()
|
57 |
|
58 |
+
# Add a small random delay before each API call
|
59 |
await asyncio.sleep(random.uniform(0.1, 0.5))
|
60 |
|
61 |
try:
|
|
|
64 |
response.raise_for_status()
|
65 |
return await response.json()
|
66 |
elif method == 'POST':
|
67 |
+
async with session.post(url, headers=headers, params=params, json=data) as response:
|
68 |
response.raise_for_status()
|
69 |
return await response.json()
|
70 |
except aiohttp.ClientResponseError as e:
|
|
|
135 |
logging.info(f"Facebook API Endpoint: {api_endpoint}")
|
136 |
|
137 |
headers = {
|
138 |
+
'Authorization': f'Bearer {api_key}'
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
+
|
141 |
+
# Extract the profile ID or username from the URL
|
142 |
+
profile_id = url.split('/')[-1].strip()
|
143 |
+
|
144 |
+
# Add the id as a query parameter
|
145 |
+
params = {'id': profile_id}
|
146 |
|
147 |
try:
|
148 |
+
result = await rate_limited_api_call(session, bucket, api_endpoint, headers, params=params, method='POST')
|
149 |
|
150 |
if 'error' not in result:
|
151 |
return {
|