QUESTION: I really appreciate in advance, shell written in python3 language. Bet
ID: 3752544 • Letter: Q
Question
QUESTION: I really appreciate in advance, shell written in python3 language. Better to solve this question steps by steps.
Restrictions You are limited to using the following Python modules os (excluding the os system function) Sys e time You must not use Python features such as the "os. system" function or the bprocess module to directly execute commands within the system shell. The purpose of this assignment is to emulate how the shell works, rather than write a in Python, not by launching a bash subprocess) If you have any questions regarding the scope of these restrictions, please ask on Python interface for the command line &e buitin commands should be implemented Ed basic command loop . reading line continuations . builtins . using variables . i/o redirection . exec-ing external commands e exec-ing with correct i/o redirection e pipes e code layout, readability, overall quality, etcExplanation / Answer
from flask import Flask, request from flask_restful import Resource, Api from sqlalchemy import create_engine from json import dumps from flask.ext.jsonpify import jsonify db_connect = create_engine('sqlite:///chinook.db') app = Flask(__name__) api = Api(app) class Employees(Resource): def get(self): conn = db_connect.connect() # connect to database query = conn.execute("select * from employees") # This line performs query and returns json result return {'employees': [i[0] for i in query.cursor.fetchall()]} # Fetches first column that is Employee ID class Tracks(Resource): def get(self): conn = db_connect.connect() query = conn.execute("select trackid, name, composer, unitprice from tracks;") result = {'data': [dict(zip(tuple (query.keys()) ,i)) for i in query.cursor]} return jsonify(result) class Employees_Name(Resource): def get(self, employee_id): conn = db_connect.connect() query = con
n.execute("select * from employees where EmployeeId =%d " %int(employee_id)) result = {'data': [dict(zip(tuple (query.keys()) ,i)) for i in query.cursor]} return jsonify(result) api.add_resource(Employees, '/employees') # Route_1 api.add_resource(Tracks, '/tracks') # Route_2 api.add_resource(Employees_Name, '/employees/<employee_id>') # Route_3 if __name__ == '__main__': app.run(port='5002')