include favorite plucker script

This commit is contained in:
Kenwood 2024-10-16 15:14:42 -04:00
parent 509e5a6b84
commit 2f50009020
1 changed files with 25 additions and 0 deletions

View File

@ -394,6 +394,31 @@ def fetch_usernames_with_favs(danbooru_url, api_key, username, limit=10):
return users_with_favs
def fetch_user_favorites(danbooru_url, api_key, username, user, limit=10):
url = f"{danbooru_url}/posts.json"
# Query for the user's favorites using the `ordfav:<username>` tag
params = {
"tags": f"ordfav:{user}", # Fetch posts favorited by the user
"limit": limit, # Number of favorites to fetch
"login": username,
"api_key": api_key,
}
# Make the request
response = requests.get(url, params=params)
if response.status_code == 200:
# Return the list of post IDs from the response
return [post["id"] for post in response.json()]
else:
print(
f"Failed to fetch favorites for '{user}'. Status code: {response.status_code}"
)
print(f"Response: {response.text}")
return []
def get_tag_from_tag_id(tag_id, api_url, api_key, username):
"""
Converts a tag_id to its corresponding tag name using the Danbooru API