forked from bengmoh/AlRahmanMosque-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
92 lines (74 loc) · 2.63 KB
/
Copy pathapp.py
File metadata and controls
92 lines (74 loc) · 2.63 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
89
90
91
92
from flask import Flask, render_template, request, redirect
from python_scripts.calculations import add_time, compare_iqama_times
import csv
import getpass
import os
import pandas as pd
import platform
# Find username of the current user
user_name = getpass.getuser()
app = Flask(__name__)
@app.before_request
def redirect_non_www():
if request.host.startswith('www.') or '127.0.0.1' in request.host:
return None # Don't redirect for localhost
# Redirect to the www. subdomain
new_url = request.url.replace('://', '://www.')
return redirect(new_url, code=301)
if os.path.exists("data/prayer_times/today_prayer_times.csv"):
df = pd.read_csv("data/prayer_times/today_prayer_times.csv")
os_type=platform.system()
if os_type == "Windows":
base_dir = f'C:\\Users\\{user_name}'
elif os_type == "Linux":
base_dir = f'/home/{user_name}'
elif os_type == "Darwin":
base_dir = f'/Users/{user_name}'
else:
raise Exception("Unsupported OS")
def find_file(filename):
for root, dirs, files in os.walk(base_dir):
if filename in files:
return os.path.join(root, filename)
return None
files_path1 = find_file("today_prayer_times.csv")
files_path2 = find_file("programs.csv")
if not files_path1 or not files_path2:
raise FileNotFoundError("Required CSV files not found.")
today = {}
with open(files_path1) as file:
reader = csv.reader(file)
for row in reader:
prayer, athan, iqama = row
today[prayer] = (athan, iqama)
programs = {}
with open(files_path2) as file:
reader = csv.reader(file)
for row in reader:
title, description, time = row
programs[title] = (description, time)
opening_time = add_time(today["Fajr"][1], -15, round_to_quarter=False)
closing_time = add_time(today["Isha"][1], 60, round_to_quarter=False)
time_changes = compare_iqama_times(
"data/prayer_times/today_prayer_times.csv",
"data/prayer_times/tomorrow_prayer_times.csv"
)
@app.route('/')
def index():
return render_template("prayer_times.html", today=today,
opening_time=opening_time,
closing_time=closing_time,
time_changes=time_changes,
programs=programs)
@app.route('/prayer-times')
def prayer_times():
return render_template("prayer_times.html", today=today)
@app.route('/donate')
def donate():
return render_template("donate.html")
@app.route('/contact')
def contact():
return render_template("contact.html",
opening_time=opening_time,
closing_time=closing_time)
app.run(debug=True)