this post was submitted on 19 Jul 2023
1 points (100.0% liked)

Python

6347 readers
2 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I've tried using pythorhead

search_results = lemmy.search(post_url)

but I get

AttributeError: 'Lemmy' object has no attribute 'search'

I've also tried requesting it myself but I don't get any results from the API even when I get it when searching for the same URL from the web interface.

@backoff.on_exception(
    backoff.expo,
    requests.exceptions.RequestException,
    max_time=MAX_BACKOFF_TIME,
)
def search(instance: str, url: str) -> Dict[str, Any]:
    api = f"https://{instance}/api/v3/search"
    query = f"?q={url}"
    response = requests.get(api + query)

    if response.status_code == 200:
        res: Dict[str, Any] = response.json()
        return res
    else:
        return {}

This makes it look more difficult than what I expected. https://programming.dev/comment/50809

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here