Spaces:
Sleeping
Sleeping
chore: Add .gitignore file and update main.py
Browse files- .gitignore +2 -0
- app/main.py +23 -12
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
*test*
|
2 |
+
.env
|
app/main.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import bs4
|
2 |
import time
|
3 |
import pytz
|
@@ -5,8 +6,11 @@ import requests
|
|
5 |
from datetime import datetime
|
6 |
from fastapi import FastAPI
|
7 |
|
8 |
-
|
9 |
-
API_URL =
|
|
|
|
|
|
|
10 |
|
11 |
def ist_time():
|
12 |
ist_timezone = pytz.timezone('Asia/Kolkata')
|
@@ -25,18 +29,25 @@ def get_data():
|
|
25 |
response = requests.get(API_URL)
|
26 |
soup = bs4.BeautifulSoup(response.text, "html.parser")
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
import uvicorn
|
|
|
1 |
+
import os
|
2 |
import bs4
|
3 |
import time
|
4 |
import pytz
|
|
|
6 |
from datetime import datetime
|
7 |
from fastapi import FastAPI
|
8 |
|
9 |
+
try:
|
10 |
+
API_URL = os.getenv("API_URL")
|
11 |
+
except Exception:
|
12 |
+
print("Using hardcoded URL")
|
13 |
+
API_URL = "https://camo.githubusercontent.com/37a440b0f0eea5e2e1c51101f9e751ea267d2e57bc0b79a241d52c7de547df45/68747470733a2f2f73706f746966792d6769746875622d70726f66696c652e76657263656c2e6170702f6170692f766965773f7569643d333134656e34696137656579636f37346876787036323534686d616d26636f7665725f696d6167653d74727565267468656d653d64656661756c742673686f775f6f66666c696e653d66616c7365266261636b67726f756e645f636f6c6f723d31323132313226696e7465726368616e67653d74727565266261725f636f6c6f723d346562313666266261725f636f6c6f725f636f7665723d74727565"
|
14 |
|
15 |
def ist_time():
|
16 |
ist_timezone = pytz.timezone('Asia/Kolkata')
|
|
|
29 |
response = requests.get(API_URL)
|
30 |
soup = bs4.BeautifulSoup(response.text, "html.parser")
|
31 |
|
32 |
+
try:
|
33 |
+
header_text = soup.find("div", class_="playing").text.split(" on")[0]
|
34 |
+
artist = soup.find("div", class_="song").text
|
35 |
+
song = soup.find("div", class_="artist").text
|
36 |
+
base64_cover = soup.findAll("img")[1].attrs["src"].split("base64,")[1].strip()
|
37 |
+
|
38 |
+
curr_time = ist_time()
|
39 |
|
40 |
+
except Exception as e:
|
41 |
+
print(e)
|
42 |
|
43 |
+
else:
|
44 |
+
return {
|
45 |
+
"header": header_text,
|
46 |
+
"song": song,
|
47 |
+
"artist": artist,
|
48 |
+
"time": curr_time,
|
49 |
+
"album_cover": base64_cover
|
50 |
+
}
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
import uvicorn
|