Update app.py
Browse files189 unmodified lines190191192193194195196197198199200201202203204205206207208209210211212213214193194195196197189 unmodified lines
@app.route('/graf_json', methods=['GET'])def get_json_file(): # Шаблон для поиска файлов file_pattern = 'week_{}_data.json' flag_pattern = 'week_{}_flag.txt' # Получаем список всех файлов, соответствующих шаблону files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('_data.json')] # Проверяем, есть ли файлы, соответствующие шаблону if files: # Отправляем последний созданный файл, только если есть файл-флаг files.sort() # Сортируем файлы по имени, чтобы получить последний latest_file = files[-1] week_number = latest_file.split('_')[1] flag_file = flag_pattern.format(week_number) if os.path.exists(flag_file): os.remove(flag_file) # Удаляем файл-флаг после отправки return send_file(latest_file, as_attachment=True) else: return "Файл еще не готов", 404 else: return "Файлы не найдены", 404def settings(): return render_template('graf.html')
app.py+2-22