File size: 1,329 Bytes
9271ad7
6b5aade
 
 
 
 
 
 
 
26a71a5
6b5aade
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4ab867
6b5aade
 
 
26a71a5
6b5aade
 
26a71a5
6b5aade
 
868a0dd
26a71a5
6b5aade
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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())