Documentation v1.0 - Pour vente
This commit is contained in:
78
app.py
78
app.py
@@ -332,81 +332,5 @@ def save_trello():
|
||||
conn.close()
|
||||
return redirect('/?page=config')
|
||||
|
||||
|
||||
|
||||
# Get budget
|
||||
@app.route('/api/budget')
|
||||
def get_budget():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT value FROM config WHERE key='budget'")
|
||||
row = c.fetchone()
|
||||
conn.close()
|
||||
return jsonify({'budget': float(row[0]) if row and row[0] else 0})
|
||||
|
||||
# Set budget
|
||||
@app.route('/api/budget', methods=['POST'])
|
||||
def set_budget():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
budget = request.form.get('budget', 0)
|
||||
c.execute('INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)', ('budget', budget))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return redirect('/?page=config')
|
||||
|
||||
# Get recurring
|
||||
@app.route('/api/recurring')
|
||||
def get_recurring():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('SELECT id, libelle, montant, category, jour FROM recurring')
|
||||
rows = c.fetchall()
|
||||
conn.close()
|
||||
return jsonify([{'id': r[0], 'libelle': r[1], 'montant': r[2], 'category': r[3], 'jour': r[4]} for r in rows])
|
||||
|
||||
# Add recurring
|
||||
@app.route('/api/recurring/add', methods=['POST'])
|
||||
def add_recurring():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('INSERT INTO recurring (libelle, montant, category, jour) VALUES (?, ?, ?, ?)',
|
||||
(request.form.get('libelle'), float(request.form.get('montant', 0)),
|
||||
request.form.get('category', 'Autre'), int(request.form.get('jour', 1))))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return redirect('/?page=config')
|
||||
|
||||
# Del recurring
|
||||
@app.route('/api/recurring/del/<int:id>')
|
||||
def del_recurring(id):
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('DELETE FROM recurring WHERE id=?', (id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return redirect('/?page=config')
|
||||
|
||||
# Get monthly stats
|
||||
@app.route('/api/stats/monthly')
|
||||
def get_monthly_stats():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('''SELECT strftime('%Y-%m', date) as month, SUM(montant) as total
|
||||
FROM depenses GROUP BY month ORDER BY month''')
|
||||
rows = c.fetchall()
|
||||
conn.close()
|
||||
return jsonify([{'month': r[0], 'total': r[1]} for r in rows])
|
||||
|
||||
# Get stats by category
|
||||
@app.route('/api/stats/category')
|
||||
def get_stats_category():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
c.execute('''SELECT category, SUM(montant) as total FROM depenses GROUP BY category''')
|
||||
rows = c.fetchall()
|
||||
conn.close()
|
||||
return jsonify([{'category': r[0] or 'Autre', 'total': r[1]} for r in rows])
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8769, debug=False)
|
||||
app.run(host='0.0.0.0', port=8769, debug=False)
|
||||
|
||||
Reference in New Issue
Block a user