api redirect for nasa astronomy picture of the day, working with dockerfile
This commit is contained in:
24
main.py
Normal file
24
main.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from requests import get
|
||||
from starlette.responses import RedirectResponse
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return RedirectResponse(main())
|
||||
|
||||
|
||||
def main():
|
||||
url = "https://apod.nasa.gov/apod/"
|
||||
response = get(url)
|
||||
html = response.text
|
||||
soup = BeautifulSoup(html, features="html.parser")
|
||||
img = soup.find('img')
|
||||
image_url = img['src']
|
||||
return url + image_url
|
||||
# with open('img.png', 'wb') as out_file:
|
||||
# response = get(url + image_url, stream=True)
|
||||
# for chunk in response:
|
||||
# out_file.write(chunk)
|
||||
Reference in New Issue
Block a user