Spaces:
Sleeping
Sleeping
Commit Β·
b1d46da
1
Parent(s): b83b5c5
Fix api issues
Browse files- pg_db.py +1 -1
- scraper.py +11 -3
pg_db.py
CHANGED
|
@@ -29,7 +29,7 @@ def _conn_params():
|
|
| 29 |
_load_env_file()
|
| 30 |
|
| 31 |
# Check if we have Supabase URL (preferred method)
|
| 32 |
-
supabase_url = os.getenv('SUPABASE_URL')
|
| 33 |
if supabase_url:
|
| 34 |
# Extract connection details from Supabase URL
|
| 35 |
# Format: postgresql://postgres:[password]@[host]:[port]/postgres
|
|
|
|
| 29 |
_load_env_file()
|
| 30 |
|
| 31 |
# Check if we have Supabase URL (preferred method)
|
| 32 |
+
supabase_url = os.getenv('SUPABASE_URL', '').strip()
|
| 33 |
if supabase_url:
|
| 34 |
# Extract connection details from Supabase URL
|
| 35 |
# Format: postgresql://postgres:[password]@[host]:[port]/postgres
|
scraper.py
CHANGED
|
@@ -9,19 +9,27 @@ import os
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
# Access the API key
|
| 12 |
-
API_KEY = os.getenv("TWITTER_API_KEY")
|
| 13 |
|
| 14 |
|
| 15 |
def search_tweets(query, query_type="Latest", limit=20):
|
| 16 |
"""
|
| 17 |
Searches for tweets using the twitterapi.io advanced search endpoint.
|
| 18 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
url = "https://api.twitterapi.io/twitter/tweet/advanced_search"
|
| 20 |
-
headers = {"X-API-Key": API_KEY}
|
| 21 |
params = {"query": query, "queryType": query_type, "limit": limit}
|
| 22 |
|
| 23 |
print(f"π Executing search with query: {query}")
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if response.status_code == 200:
|
| 27 |
return response.json()
|
|
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
# Access the API key
|
| 12 |
+
API_KEY = os.getenv("TWITTER_API_KEY", "").strip()
|
| 13 |
|
| 14 |
|
| 15 |
def search_tweets(query, query_type="Latest", limit=20):
|
| 16 |
"""
|
| 17 |
Searches for tweets using the twitterapi.io advanced search endpoint.
|
| 18 |
"""
|
| 19 |
+
if not API_KEY:
|
| 20 |
+
print("β Error: TWITTER_API_KEY not found or empty")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
url = "https://api.twitterapi.io/twitter/tweet/advanced_search"
|
| 24 |
+
headers = {"X-API-Key": API_KEY.strip()}
|
| 25 |
params = {"query": query, "queryType": query_type, "limit": limit}
|
| 26 |
|
| 27 |
print(f"π Executing search with query: {query}")
|
| 28 |
+
try:
|
| 29 |
+
response = requests.get(url, headers=headers, params=params)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"β Request error: {e}")
|
| 32 |
+
return None
|
| 33 |
|
| 34 |
if response.status_code == 200:
|
| 35 |
return response.json()
|