forked from sookcha/every2cal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
102 lines (81 loc) ยท 2.97 KB
/
index.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
98
99
100
101
102
import os
import logging
from flask import Flask, render_template, request, send_file
import boto3
import everytime
from convert import Convert
import dotenv
ACCESS_KEY_ID = os.environ['EVERY_CAL_ACCESS_KEY_ID']
SECRET_KEY_ID = os.environ['EVERY_CAL_SECRET_KEY_ID']
BUCKET_NAME = os.environ['BUCKET_NAME']
app = Flask(__name__)
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def upload_to_s3(file_path, bucket_name, s3_path):
s3 = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=SECRET_KEY_ID
)
s3.upload_file(file_path, bucket_name, s3_path)
@app.route("/")
@app.route("/home")
def index():
return render_template("index.html")
@app.route('/dwn_cal', methods=['GET', 'POST'])
def dwn_cal():
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
schd_url = request.args.get('schd_url')
if not start_date or not end_date or not schd_url:
return "Missing required parameters", 400
start_date = ''.join(start_date.split('-'))
end_date = ''.join(end_date.split('-'))
schd_url = schd_url[22:]
logger.info(f"Processing timetable: {schd_url} from {start_date} to {end_date}")
try:
e = everytime.Everytime(schd_url)
xml = e.get_timetable()
c = Convert(xml)
calendar_path = c.get_calendar(c.get_subjects(), start_date, end_date, schd_url)
path = f'/tmp/{schd_url}.ics'
upload_to_s3(path, BUCKET_NAME, f"ical/{os.path.basename(path)}")
return send_file(path, as_attachment=True)
except Exception as e:
logger.error(f"Error processing timetable: {e}")
return '''
<div class="main-head">
<h1>๋ก๊ทธ์ธ ์ ๋ณด ํน์ ์๊ฐํ ์กด์ฌ ์ ๋ฌด๋ฅผ ๋ค์ ํ์ธํด์ฃผ์ธ์.</h1>
</div>
<div class="google-forms">
<iframe
src="https://docs.google.com/forms/d/e/1FAIpQLSeZnoKueveJLDLz-81uHB9r-FXqHm_HZuMTwQ6tGk6eTsQdmg/viewform?embedded=true"
width="640" height="1088" frameborder="0" marginheight="0" marginwidth="0">๋ก๋ ์คโฆ</iframe>
</div>
<style>
.google-forms {
margin: auto;
width: max-content;
}
.main-head {
margin: auto;
width: max-content;
}
</style>
'''
@app.route('/privacypolicy', methods=['GET'])
def privacy_policy():
return render_template('privacypolicy.html')
@app.route('/opensourcelicense', methods=['GET'])
def opensource_license():
return render_template('opensourcelicense.html')
@app.route('/robots.txt', methods=['GET'])
def robots_txt():
return render_template('robots.txt')
@app.route('/sitemap.xml', methods=['GET'])
def sitemap_xml():
return render_template('sitemap.xml')
if __name__ == '__main__':
if os.path.exists('.env'): dotenv.load_dotenv()
app.run(host='0.0.0.0', port=8888, debug=False)