def delete_student(indexId): student = Student.query.filter_by(id=indexId).first() if not student: return jsonify({'message': 'No user found'}) db.session.delete(student) db.session.commit() return jsonify({'message': 'Student found and Deleted'})
def case(): country = request.args.get('country') try: return jsonify({ "total Cases": findinfo(country)[0], "Total Death": findinfo(country)[1], "Total Recovered": findinfo(country)[2] }) except: return jsonify({"Not Available": " "})
def update_results(indexId): student = Student.query.filter_by(id=indexId).first() if not student: return jsonify({'message': 'No Student found'}) student.name = request.json['name'] student.physics = request.json.get('physics', "") student.maths = request.json.get('maths', "") student.chemistry = request.json.get('chemistry', "") db.session.commit() return jsonify({'student': 'Pass'})
def temp_range(start_date, end_date): #query temps = session.query(func.min(Measurement.tobs), func.max(Measurement.tobs), func.avg(Measurement.tobs)).filter( Measurement.date >= start_date, Measurement.date <= end_date).first() #create dictionary from result temps_dictionary2 = {"TMIN": temps[0], "TMAX": temps[1], "TAVG": temps[2]} return jsonify(temps_dictionary2)
def fetch(query): api_key = environ.get('MOVIE_API_KEY') query = "Up" url = f'https://api.themoviedb.org/3/search/movie/?api_key={api_key}&language=en-US&page=1&query={query}' response = requests.get(url).json() return jsonify(response)
def temp_stats(start_date): #query using start date temps = session.query(func.min(Measurement.tobs), func.max(Measurement.tobs), func.avg(Measurement.tobs)).filter( Measurement.date >= start_date).first() #create dictionary from result temps_dictionary1 = { "minimum temperuture": temps[0], "maximum temperature": temps[1], "average temperature": temps[2] } return jsonify(temps_dictionary1)
def stations(): #list for station data stations_list = [] #query stations = session.query(Stations.station, Stations.name, Stations.latitude, Stations.longitude, Stations.elevation).all() #create a dictionary for each station's info and append to list for station in stations: station_dict = { "station_id": station[0], "name": station[1], "latitude": station[2], "longitude": station[3], "elevation": station[4] } stations_list.append(station_dict) # return to user return jsonify(stations_list)
def temperature(): recent_date = (session.query(measurment.date).order_by( measurment.date.desc()).first()) recent_date = list(np.ravel(recent_date))[0] recent_date = dt.datetime.strptime(recent_date, '%Y-%m-%d') previous_year = recent_date - dt.timedelta(days=365) most_active = session.query(measurment.station, func.count(measurment.Station))\ .filter(measurment.date >= previous_year)\ .group_by(measurment.station)\ .order_by(func.count(measurment.station)).desc().first() temps = session.query( measurment.tobs).filter(measurment.station == most_active[0]).filter( measurment.date >= previous_year) temp_results = [result[0] for result in temps] return jsonify(temp_results)
def percipitaiton(): recent_date = (session.query(measurment.date).order_by( measurment.date.desc()).first()) recent_date = list(np.ravel(recent_date))[0] recent_date = dt.datetime.strptime(recent_date, '%Y-%m-%d') previous_year = recent_date - dt.timedelta(days=365) percip_data = (session.query(measurment.date, measurment.prcp)\ .filter(measurment.date > previous_year)\ .order_by(measurment.date).all()) percip_results = [] for result in percip_data: row = {} row[measurment.date] = row[measurment.prcp] percip_results.append(row) return jsonify(percip_results)
def index(): if (request.method == 'POST'): some_json = request.get_json() return jsonify({'you sent': some_json}), 281 else: return jsonify({"about": "Hello World!"})
def get_multiply10(num): return jsonify({'result': num * 10})
def stations(): Station_results = session.query(station.station, station.name).all() return jsonify(Station_results)
def date_range(start, end): range_results = session.query(func.min(measurment.tobs), func.avg(measurment.tobs),func.max(measurment.tobs))\ .filter(measurment.date >= start).filter(measurment.date <= end).all() return jsonify(range_results)
def start_day(start): start_results = session.query(func.min(measurment.tobs), func.avg(measurment.tobs), func.max(measurment.tobs))\ .filter(measurment.date >= start).all() return jsonify(start_results)
inputfile='tempi.txt', expectedoutput='tempo.txt', timeout=5, check=True ) d = {'username': username, 'problem_id':problem_id, 'verdict':verdict} codeno,msg = insertingInsolve(d) except: return 420, "some error" #closing temporary files finally: tempi.close() tempo.close() if codeno==200: d1['msg']="verdict added to solve table" return jsonify(d1) else: return jsonify(d2) else: return jsonify(d2)
def queue(): return jsonify(os.listdir(self.folder)) @app.route("/newjob"):
def precip_json(): #call prcp_or temps function with proper datapoint results = prcp_or_temps(Measurement.prcp) return jsonify(results)