-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (63 loc) · 3.06 KB
/
app.py
File metadata and controls
88 lines (63 loc) · 3.06 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from datetime import datetime
from flask import Flask, render_template
from flask import jsonify
from flask import request
import requests
import lxml
from bs4 import BeautifulSoup as soup
""" Simple Flask application """
app = Flask(__name__)
happy_smiley_b64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAnXAAAJ1wGxbhe3AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAgZJREFUOI2lkj9oU2EUxX/3S4JNWqsJBaGIBWnpkkShk7o1RXAICE0KLmIL0kUQ6ebs4CRFXYpRiw5iXjOJOPhncSgOYkgr2KaiQnGQQkL/5KVp37sOyYtpiFPvdi7nnu/cez44ZEmnZv9IMlTZ6xozyiCIuqLfQ4Hqu9+fX1Xaub52wUg0NbPnBHLAKQVboRdI7jv+u6ET0X37z9dP/3Mg4djEc1QHHL87tZnPFVuJvWfHh3yueYrqj9LSwlVADwhEoqkZRS6XqttjrL3Z7bjw4KUj4WDPBxW1yoWF2aZA/0gyZO92/XL87vnNfK6YntMYgDUtSwCtuC+eHnaUj909DKwvWrYBsPeCCRW+eLbVkFRD0nu4FW8UrBWBws4WowB+AHEZBvLeQI+fe63O27ErkjfoMPDaNFqqRoxHqNkE5yel6uH5SanWbIJNBVUBUQBTt2hWUY0DpDMaqQVYST/SUY+fymiiFuBbOqORxtAZVV09eMRa10/H517YzOeKqcd6EeUhyjHqeZUN3LCuy9v2I/6LMTZxS0XHS5XthBfjlTntA3gxLRsHYlR5WV7O3m86aJSEY6lnIKd9wtRGwVppPVzj5SeorJWWs9do/0ieyPF46qao3BYouGihvrPEFeKqcqe8nH3gDXcSAODkuXRwZ0sTImaofnS32H1U3q8vWnYn/qHqL8V35T417C5JAAAAAElFTkSuQmCC"
smiley_img = f'<img src="{happy_smiley_b64}">'
def parse_lord_words(html_source: str) -> dict:
if not isinstance(html_source, str):
return {'error': 'source is not a string'}
data = soup(html_source, 'lxml')
div = data.find_all('div', class_='ewangelia')
bible_quote = ''.join([result.text for result in div])
if bible_quote:
return {'bible': bible_quote}
return {'bible': "?"}
@app.route('/')
def hello_world(): # put application's code here
curr_datetime = datetime.now()
hour = curr_datetime.hour
minut = curr_datetime.minute
second = curr_datetime.second
year = curr_datetime.year
month = curr_datetime.month
day = curr_datetime.day
nowis = f"{year}.{month}.{day} {hour}:{minut}.{second}<br><br>"
progress = "<br>" + "_" * 10 + "<br>"
progress += f"{month} {str(smiley_img * month)}<br>"
progress += f"{day} {str(smiley_img * day)}<br>"
progress += "<hr>"
progress += f"{hour} {str(smiley_img * hour)}<br>"
progress += f"{minut} {str(smiley_img * minut)}<br>"
progress += f"{second} {str(smiley_img * second)}<br>"
text = f"{nowis}{progress}"
return f'On world<br><hr>{text}'
@app.route('/bible')
def bible_words():
html = requests.get('https://opoka.org.pl/liturgia/')
return html.text
@app.route('/bible/words')
def show_bible_quote():
html = requests.get('https://opoka.org.pl/liturgia/')
if html.text and html.text != "":
return parse_lord_words(html.text)
return {'error': 'No source available'}
@app.route('/ip')
def show_ip():
"""Get client IP adress
Another way: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
"""
return jsonify({'ip': request.access_route[-1]}), 200
@app.route('/board')
def board():
return render_template('board.html')
@app.route('/weather')
def show_weather():
return render_template("simpleteons/weather.html")
if __name__ == '__main__':
app.run()