Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, Response
- import sqlite3
- from operator import itemgetter
- app = Flask(__name__)
- app.should_ignore_error(True)
- @app.route("/schedule")
- def schcedule_route():
- return get_data()
- def get_data():
- try:
- with open("data.txt", "r") as read_file:
- file = read_file.read().split("\n")
- db_path = file[0]
- year = file[1]
- except Exception as e:
- return [str(e)]
- try:
- conn = sqlite3.connect(db_path)
- except Exception as e:
- return [str(e)]
- try:
- c = conn.cursor()
- except Exception as e:
- return [str(e)]
- try:
- c.execute("SELECT * FROM spaceships WHERE year = ?", (year,))
- except Exception as e:
- return [str(e)]
- try:
- result = []
- except Exception as e:
- return [str(e)]
- try:
- for el in c.fetchall():
- result.append({
- "id": el[0],
- "name": el[1],
- "load": el[2],
- "crew": el[3],
- "year": el[4]
- })
- except Exception as e:
- return [str(e)]
- try:
- result.sort(key=itemgetter("load", "name"))
- except Exception as e:
- return [str(e)]
- try:
- c.close()
- except Exception as e:
- return [str(e)]
- try:
- return result
- except Exception as e:
- return [str(e)]
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement