arpy8 commited on
Commit
6b5aade
1 Parent(s): 004e147

added files

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app/main.py +47 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY ./app /code/app
10
+
11
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import bs4
2
+ import time
3
+ import pytz
4
+ import requests
5
+ from datetime import datetime
6
+ from fastapi import FastAPI
7
+
8
+
9
+ API_URL = "https://camo.githubusercontent.com/37a440b0f0eea5e2e1c51101f9e751ea267d2e57bc0b79a241d52c7de547df45/68747470733a2f2f73706f746966792d6769746875622d70726f66696c652e76657263656c2e6170702f6170692f766965773f7569643d333134656e34696137656579636f37346876787036323534686d616d26636f7665725f696d6167653d74727565267468656d653d64656661756c742673686f775f6f66666c696e653d66616c7365266261636b67726f756e645f636f6c6f723d31323132313226696e7465726368616e67653d74727565266261725f636f6c6f723d346562313666266261725f636f6c6f725f636f7665723d74727565"
10
+
11
+ def ist_time():
12
+ ist_timezone = pytz.timezone('Asia/Kolkata')
13
+ ist_time = datetime.now(ist_timezone).strftime("%H:%M")
14
+ return ist_time
15
+
16
+
17
+ app = FastAPI(title="was hört arpy8 gerade?")
18
+
19
+ @app.get("/")
20
+ def display() -> str:
21
+ return "Hola amigo! I am alive."
22
+
23
+ @app.get("/data")
24
+ def get_data():
25
+ response = requests.get(API_URL)
26
+ soup = bs4.BeautifulSoup(response.text, "html.parser")
27
+
28
+ header_text = soup.find("div", class_="playing").text.split(" on")[0]
29
+ artist = soup.find("div", class_="song").text
30
+ song = soup.find("div", class_="artist").text
31
+
32
+ curr_time = ist_time()
33
+
34
+ return {
35
+ "header": header_text,
36
+ "artist": artist,
37
+ "song": song,
38
+ "time": curr_time
39
+ }
40
+
41
+ if __name__ == "__main__":
42
+ import uvicorn
43
+ uvicorn.run(app)
44
+
45
+ # while 1:
46
+ # time.sleep(0.2)
47
+ # print(get_data())
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ requests==2.31.0
2
+ pytz==2023.3.post1
3
+ fastapi==0.104.1
4
+ uvicorn==0.24.0
5
+ beautifulsoup4==4.12.2