-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
97 lines (68 loc) · 2.54 KB
/
app.py
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
89
90
91
92
93
94
95
96
97
import requests
from bs4 import BeautifulSoup as bs
import os
from flask import Flask, request, render_template
from flask_socketio import SocketIO
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
app = Flask(__name__)
socketio = SocketIO(app)
# -------------------------------------------------
@app.route('/news')
def news():
link = 'https://inshorts.com/en/read'
req = requests.get(link)
soup = bs(req.content, 'html5lib')
box = soup.findAll('div', attrs = {'class':'news-card z-depth-1'})
ha,ia,ba,la = [],[],[],[]
for i in range(len(box)):
h = box[i].find('span', attrs = {'itemprop':'headline'}).text
m = box[i].find('div', attrs = {'class':'news-card-image'})
m = m['style'].split("'")[1]
b = box[i].find('div', attrs = {'itemprop':'articleBody'}).text
l='link not found'
try:
l = box[i].find('a', attrs = {'class':'source'})['href']
except:
pass
ha.append(h)
ia.append(m)
ba.append(b)
la.append(l)
return render_template('news.html', ha=ha, ia=ia, ba=ba, la=la, len = len(ha))
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
# ==============================================================
@app.route('/')
def iotled():
from vicksbase import firebase as vix
firebase_obj = vix.FirebaseApplication('https://home-automation-336c0-default-rtdb.firebaseio.com/', None)
result1 = firebase_obj.get('A/B/C/Switch', None)
data1="{}".format(result1)
if data1 == '1':
img = 'static/logo/bulbon.jpg'
else:
img = '../static/logo/bulboff.jpg'
return render_template("iotled.html",
data=data1,
img = img
)
@app.route('/converted_iotled', methods=['POST'])
def converted_iotled():
from vicksbase import firebase as vix
firebase_obj = vix.FirebaseApplication('https://home-automation-336c0-default-rtdb.firebaseio.com/', None)
data = int(request.form['iotled'])
firebase_obj.put('A/B/C','Switch', data)
result1 = firebase_obj.get('led1', None)
data1="{}".format(result1)
if data1 == '1':
img = 'static/logo/bulbon.jpg'
else:
img = '../static/logo/bulboff.jpg'
return render_template("iotled.html",
data=data1,
img = img
)
# ============================================
if __name__ == '__main__':
socketio.run(app, debug=True)