Spaces:
Sleeping
Sleeping
File size: 4,342 Bytes
5bda095 79c9006 5bda095 79c9006 5bda095 79c9006 5bda095 8f9883c 5bda095 79c9006 5bda095 79c9006 5bda095 79c9006 5bda095 |
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
import os
import folium
from flask import Flask, render_template, jsonify, request, redirect, url_for, session
import firebase_admin
from firebase_admin import credentials, firestore
# Initialize Flask app
app = Flask(__name__)
app.secret_key = os.urandom(24) # For session management
# Initialize Firebase
# try:
# firebase_admin.get_app()
# except ValueError:
# cred = credentials.Certificate({
# "type": "service_account",
# "project_id": "snippetscript-37175",
# "private_key_id": "your_private_key_id",
# "private_key": "your_private_key",
# "client_email": "your_client_email",
# "client_id": "your_client_id",
# "auth_uri": "https://accounts.google.com/o/oauth2/auth",
# "token_uri": "https://oauth2.googleapis.com/token",
# "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
# "client_x509_cert_url": "your_cert_url"
# })
# firebase_admin.initialize_app(cred)
# Initialize Firestore
# db = firestore.client()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/user-dashboard.html')
def user_dashboard():
return render_template('user-dashboard.html')
@app.route('/get-previous-results', methods=['GET'])
def get_previous_results():
try:
# Simulating a ThingSpeak API call or shared data
# response = requests.get("https://api.thingspeak.com/...", params=...)
# thingspeak_data = response.json()
# Returning shared data for all users
return jsonify({"status": "success", "data": thingspeak_data})
except Exception as e:
return jsonify({"status": "error", "message": str(e)})
# @app.route('/login', methods=['POST'])
# def login():
# phone = request.form['loginPhone']
# password = request.form['loginPassword']
# # Query Firestore to find user
# users_ref = db.collection('users')
# query = users_ref.where('phone', '==', phone).where('password', '==', password)
# try:
# users = query.stream()
# user_list = list(users)
# if len(user_list) > 0:
# # User found, start session
# session['user_phone'] = phone
# return redirect(url_for('user_dashboard'))
# else:
# return "Invalid credentials", 401
# except Exception as e:
# return str(e), 500
# @app.route('/dashboard')
# def user_dashboard():
# if 'user_phone' not in session:
# return redirect(url_for('index'))
# # Fetch user details from Firestore
# user_ref = db.collection('users').document(session['user_phone'])
# user = user_ref.get()
# if user.exists:
# user_data = user.to_dict()
# return render_template('user-dashboard.html', user=user_data)
# else:
# return "User not found", 404
# @app.route('/admin.html')
# def admin():
# return render_template('admin.html')
@app.route('/admin.html')
def admin():
# Create a map centered on Delhi
delhi_coordinates = [28.6139, 77.2090]
folium_map = folium.Map(location=delhi_coordinates, zoom_start=12)
# Add predefined markers in Delhi
markers = [
{"name": "India Gate", "coordinates": [28.6129, 77.2295]},
{"name": "Red Fort", "coordinates": [28.6562, 77.2410]},
{"name": "Qutub Minar", "coordinates": [28.5245, 77.1855]},
]
# Add markers to the map
for marker in markers:
folium.Marker(
location=marker["coordinates"],
popup=marker["name"],
icon=folium.Icon(color="blue", icon="info-sign"),
).add_to(folium_map)
# Use a valid Folium tile layer
folium.TileLayer('OpenStreetMap').add_to(folium_map)
# Add Layer Control for toggling between tile layers
folium.LayerControl().add_to(folium_map)
# Generate the map HTML
map_html = folium_map._repr_html_()
# Render the template with the map
return render_template('admin.html', map=map_html)
@app.route('/logout')
def logout():
# Remove the user's phone number from the session
session.pop('user_phone', None)
# Redirect to the index route (function name, not the file name)
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True) |