同步操作将从 编程语言算法集/Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
requests with httpx (#12744)
# /// script# requires-python = ">=3.13"# dependencies = [# "httpx",# ]# ///import httpxdef get_apod_data(api_key: str) -> dict:"""Get the APOD(Astronomical Picture of the day) dataGet your API Key from: https://api.nasa.gov/"""url = "https://api.nasa.gov/planetary/apod"return httpx.get(url, params={"api_key": api_key}, timeout=10).json()def save_apod(api_key: str, path: str = ".") -> dict:apod_data = get_apod_data(api_key)img_url = apod_data["url"]img_name = img_url.split("/")[-1]response = httpx.get(img_url, timeout=10)with open(f"{path}/{img_name}", "wb+") as img_file:img_file.write(response.content)del responsereturn apod_datadef get_archive_data(query: str) -> dict:"""Get the data of a particular query from NASA archives"""url = "https://images-api.nasa.gov/search"return httpx.get(url, params={"q": query}, timeout=10).json()if __name__ == "__main__":print(save_apod("YOUR API KEY"))apollo_2011_items = get_archive_data("apollo 2011")["collection"]["items"]print(apollo_2011_items[0]["data"][0]["description"])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。