-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·125 lines (88 loc) · 3.07 KB
/
app.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import warnings
import subprocess
import time
import database
from docx import Document
from flask import Flask, jsonify, request, abort
warnings.filterwarnings("ignore")
app = Flask(__name__)
items = []
@app.route('/')
def index():
return "Hello, World!"
@app.route('/api/v1.0/matiere', methods=['GET'])
def get_matieres():
database.getmatieres()
result = database.resultsExportMatieres
print (result)
return jsonify({'item': result}), 201
@app.route('/api/v1.0/matiere', methods=['POST'])
def create_matiere():
database.creatematiere(request.json)
return jsonify({'item': 'matiere cree'}), 201
@app.route('/api/v1.0/etudiant', methods=['GET'])
def get_etudiants():
database.getetudiants()
result = database.resultsExportEtudiants
print (result)
return jsonify({'item': result}), 201
@app.route('/api/v1.0/etudiant', methods=['POST'])
def create_etudiant():
database.createetudiant(request.json)
return jsonify({'item': 'etudiant cree'}), 201
@app.route('/api/v1.0/note', methods=['GET'])
def get_notes():
database.getnotes()
result = database.resultsExportNotes
print (result)
return jsonify({'item': result}), 201
@app.route('/api/v1.0/note', methods=['POST'])
def create_note():
database.createnote(request.json)
return jsonify({'item': 'note cree'}), 201
@app.route('/api/v1.0/noteetu/', methods=['GET'])
def get_notes_etu():
#if not request.json or not 'id_etu' in request.args.get('username'):
# abort(400)
database.getnotesetu(int(request.args.get('id_etu')))
result = database.resultsExportNotesEtu
document = Document()
document.add_heading('Bulletin MASTER 2 INFO', 0)
document.add_paragraph('')
document.add_paragraph('Etudiant')
document.add_paragraph('Matricule: ' + result[0]['mat'])
document.add_paragraph('Nom: ' + result[0]['nom'])
document.add_paragraph('Prenoms: ' + result[0]['pren'])
document.add_paragraph('')
table = document.add_table(rows=1, cols=4)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Matiere'
hdr_cells[1].text = 'Coefficient'
hdr_cells[2].text = 'Note'
hdr_cells[3].text = 'Total'
totalNote = 0
coefficientNote = 0
totals = 0
for item in result:
row_cells = table.add_row().cells
row_cells[0].text = str(item['lib'])
row_cells[1].text = str(item['coef'])
row_cells[2].text = str(item['note'])
row_cells[3].text = str(item['note']*item['coef'])
totalNote += item['note']
coefficientNote += item['coef']
totals += (item['coef']*item['note'])
totalMoyenne = totals / coefficientNote
ft_cells = table.add_row().cells
ft_cells[0].text = str("")
ft_cells[1].text = str("")
ft_cells[2].text = str("Total")
ft_cells[3].text = str(totalMoyenne)
document.add_page_break()
document.save('/tmp/demo.docx')
process = subprocess.Popen(['libreoffice', '', '/tmp/demo.docx'])
time.sleep(2)
process.kill()
return jsonify({'item': 'bulletin ok'}), 201
if __name__ == '__main__':
app.run(debug=True)