-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
77 lines (63 loc) · 2.03 KB
/
app.py
File metadata and controls
77 lines (63 loc) · 2.03 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
from flask import Flask, render_template, request, redirect, url_for, send_file
import json
import csv
app = Flask(__name__)
FILE_NAME = 'jobs.json'
# Helper functions to load and save jobs
def load_jobs():
try:
with open(FILE_NAME, 'r') as f:
return json.load(f)
except FileNotFoundError:
return []
def save_jobs(jobs):
with open(FILE_NAME, 'w') as f:
json.dump(jobs, f)
# Load jobs from file
jobs = load_jobs()
@app.route('/')
def home():
return render_template('index.html', jobs=jobs)
@app.route('/add', methods=['POST'])
def add_job():
job_title = request.form['job_title']
company_name = request.form['company_name']
status = request.form['status']
jobs.append({
'job_title': job_title,
'company_name': company_name,
'status': status,
'done': False
})
save_jobs(jobs)
return redirect(url_for('home'))
@app.route('/delete/<int:index>', methods=['POST'])
def delete_job(index):
if 0 <= index < len(jobs):
jobs.pop(index)
save_jobs(jobs)
return redirect(url_for('home'))
@app.route('/done/<int:index>', methods=['POST'])
def mark_done(index):
if 0 <= index < len(jobs):
jobs[index]['done'] = True
save_jobs(jobs)
return redirect(url_for('home'))
# Export jobs to CSV
@app.route('/export', methods=['GET'])
def export_jobs():
filename = 'jobs_export.csv'
with open(filename, 'w', newline='') as csvfile:
fieldnames = ['Job Title', 'Company Name', 'Status', 'Done']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for job in jobs:
writer.writerow({
'Job Title': job['job_title'],
'Company Name': job['company_name'],
'Status': job['status'],
'Done': job['done']
})
return send_file(filename, as_attachment=True)
if __name__ == '__main__':
app.run(debug=True)