import os import bs4 import time import pytz import requests from datetime import datetime from fastapi import FastAPI API_URL = "https://spotify-github-profile.kittinanx.com/api/view?uid=314en4ia7eeyco74hvxp6254hmam&cover_image=true&theme=default&show_offline=false&background_color=121212&interchange=true&bar_color_cover=true" def ist_time(): ist_timezone = pytz.timezone('Asia/Kolkata') ist_time = datetime.now(ist_timezone).strftime("%H:%M") return ist_time app = FastAPI(title="was hört arpy8 gerade?") @app.get("/") def display() -> str: return "Hola amigo! I am alive." @app.get("/data") def get_data(): response = requests.get(API_URL) soup = bs4.BeautifulSoup(response.text, "html.parser") curr_time = ist_time() header_text = soup.find("div", class_="playing").text.split(" on")[0] artist = soup.find("div", class_="song").text song = soup.find("div", class_="artist").text base64_cover = soup.findAll("img")[1].attrs["src"].split("base64,")[1].strip() return { "time": curr_time, "header": header_text, "song": song, "artist": artist, "album_cover": base64_cover, } if __name__ == "__main__": import uvicorn uvicorn.run(app) # while 1: # time.sleep(0.2) # print(get_data())