more prints
This commit is contained in:
25
main.py
25
main.py
@@ -28,16 +28,21 @@ async def get_latest_post(subreddit):
|
|||||||
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/0.1)"}
|
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/0.1)"}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
try:
|
if response.headers.get("Content-Type", "").startswith("application/json"):
|
||||||
data = response.json()
|
try:
|
||||||
print(f"Fetched data from Reddit: {data}")
|
data = response.json()
|
||||||
if data["data"]["children"]:
|
print(f"Fetched data from Reddit: {data}")
|
||||||
for child in data["data"]["children"]:
|
if data["data"]["children"]:
|
||||||
post = child["data"]
|
for child in data["data"]["children"]:
|
||||||
if post.get("post_hint") == "image" and post.get("url", "").endswith((".jpg", ".png", ".jpeg", ".gif")):
|
post = child["data"]
|
||||||
print(f"Found image post: {post['title']} - {post['url']}")
|
if post.get("post_hint") == "image" and post.get("url", "").endswith((".jpg", ".png", ".jpeg", ".gif")):
|
||||||
return post["title"], post["url"]
|
print(f"Found image post: {post['title']} - {post['url']}")
|
||||||
except (KeyError, json.JSONDecodeError):
|
return post["title"], post["url"]
|
||||||
|
except (KeyError, json.JSONDecodeError):
|
||||||
|
return None, None
|
||||||
|
else:
|
||||||
|
print(f"Unexpected content type from Reddit: {response.headers.get('Content-Type')}")
|
||||||
|
print(f"Response content: {response.text}")
|
||||||
return None, None
|
return None, None
|
||||||
else:
|
else:
|
||||||
print(f"Failed to fetch Reddit data (maybe a block?): {response.status_code}")
|
print(f"Failed to fetch Reddit data (maybe a block?): {response.status_code}")
|
||||||
|
|||||||
Reference in New Issue
Block a user