Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,96 @@
|
|
1 |
-
|
2 |
import folium
|
|
|
|
|
|
|
3 |
|
|
|
4 |
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
@app.route('/')
|
7 |
def index():
|
8 |
return render_template('index.html')
|
9 |
|
10 |
-
@app.route('/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def admin():
|
12 |
# Create a map centered on Delhi
|
13 |
delhi_coordinates = [28.6139, 77.2090]
|
@@ -40,5 +123,15 @@ def admin():
|
|
40 |
# Render the template with the map
|
41 |
return render_template('admin.html', map=map_html)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
if __name__ == '__main__':
|
44 |
-
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
1 |
+
import os
|
2 |
import folium
|
3 |
+
from flask import Flask, render_template, jsonify, request, redirect, url_for, session
|
4 |
+
import firebase_admin
|
5 |
+
from firebase_admin import credentials, firestore
|
6 |
|
7 |
+
# Initialize Flask app
|
8 |
app = Flask(__name__)
|
9 |
+
app.secret_key = os.urandom(24) # For session management
|
10 |
+
|
11 |
+
# Initialize Firebase
|
12 |
+
# try:
|
13 |
+
# firebase_admin.get_app()
|
14 |
+
# except ValueError:
|
15 |
+
# cred = credentials.Certificate({
|
16 |
+
# "type": "service_account",
|
17 |
+
# "project_id": "snippetscript-37175",
|
18 |
+
# "private_key_id": "your_private_key_id",
|
19 |
+
# "private_key": "your_private_key",
|
20 |
+
# "client_email": "your_client_email",
|
21 |
+
# "client_id": "your_client_id",
|
22 |
+
# "auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
23 |
+
# "token_uri": "https://oauth2.googleapis.com/token",
|
24 |
+
# "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
25 |
+
# "client_x509_cert_url": "your_cert_url"
|
26 |
+
# })
|
27 |
+
# firebase_admin.initialize_app(cred)
|
28 |
+
|
29 |
+
# Initialize Firestore
|
30 |
+
# db = firestore.client()
|
31 |
|
32 |
@app.route('/')
|
33 |
def index():
|
34 |
return render_template('index.html')
|
35 |
|
36 |
+
@app.route('/user-dashboard.html')
|
37 |
+
def user_dashboard():
|
38 |
+
return render_template('user-dashboard.html')
|
39 |
+
|
40 |
+
@app.route('/get-previous-results', methods=['GET'])
|
41 |
+
def get_previous_results():
|
42 |
+
try:
|
43 |
+
# Simulating a ThingSpeak API call or shared data
|
44 |
+
# response = requests.get("https://api.thingspeak.com/...", params=...)
|
45 |
+
# thingspeak_data = response.json()
|
46 |
+
|
47 |
+
# Returning shared data for all users
|
48 |
+
return jsonify({"status": "success", "data": thingspeak_data})
|
49 |
+
except Exception as e:
|
50 |
+
return jsonify({"status": "error", "message": str(e)})
|
51 |
+
|
52 |
+
# @app.route('/login', methods=['POST'])
|
53 |
+
# def login():
|
54 |
+
# phone = request.form['loginPhone']
|
55 |
+
# password = request.form['loginPassword']
|
56 |
+
|
57 |
+
# # Query Firestore to find user
|
58 |
+
# users_ref = db.collection('users')
|
59 |
+
# query = users_ref.where('phone', '==', phone).where('password', '==', password)
|
60 |
+
|
61 |
+
# try:
|
62 |
+
# users = query.stream()
|
63 |
+
# user_list = list(users)
|
64 |
+
|
65 |
+
# if len(user_list) > 0:
|
66 |
+
# # User found, start session
|
67 |
+
# session['user_phone'] = phone
|
68 |
+
# return redirect(url_for('user_dashboard'))
|
69 |
+
# else:
|
70 |
+
# return "Invalid credentials", 401
|
71 |
+
|
72 |
+
# except Exception as e:
|
73 |
+
# return str(e), 500
|
74 |
+
|
75 |
+
# @app.route('/dashboard')
|
76 |
+
# def user_dashboard():
|
77 |
+
# if 'user_phone' not in session:
|
78 |
+
# return redirect(url_for('index'))
|
79 |
+
|
80 |
+
# # Fetch user details from Firestore
|
81 |
+
# user_ref = db.collection('users').document(session['user_phone'])
|
82 |
+
# user = user_ref.get()
|
83 |
+
|
84 |
+
# if user.exists:
|
85 |
+
# user_data = user.to_dict()
|
86 |
+
# return render_template('user-dashboard.html', user=user_data)
|
87 |
+
# else:
|
88 |
+
# return "User not found", 404
|
89 |
+
|
90 |
+
# @app.route('/admin.html')
|
91 |
+
# def admin():
|
92 |
+
# return render_template('admin.html')
|
93 |
+
@app.route('/admin.html')
|
94 |
def admin():
|
95 |
# Create a map centered on Delhi
|
96 |
delhi_coordinates = [28.6139, 77.2090]
|
|
|
123 |
# Render the template with the map
|
124 |
return render_template('admin.html', map=map_html)
|
125 |
|
126 |
+
@app.route('/logout')
|
127 |
+
def logout():
|
128 |
+
# Remove the user's phone number from the session
|
129 |
+
session.pop('user_phone', None)
|
130 |
+
|
131 |
+
# Redirect to the index route (function name, not the file name)
|
132 |
+
return redirect(url_for('index'))
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
if __name__ == '__main__':
|
137 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|