class AllCrimeData(Resource): decorators = [auth.login_required] def get(self): return read_aurin_result_data("/crime-data/result-crime-2019.json") class CrimeMeta(Resource): decorators = [auth.login_required] def get(self): return read_aurin_result_data("/crime-data/result-meta.json") api.add_resource(AllCrimeData, "/crime", endpoint='crime') api.add_resource(CrimeMeta, "/crime/meta", endpoint='crime/meta') # **************************************************************************** # hospital-education-foreigner data starts # **************************************************************************** class AllHEFData(Resource): decorators = [auth.login_required] def get(self): return read_aurin_result_data( "/hospital-education-foreigner-data/result-hospital-education-foreigner.json" )
if admin_check(): return f(*args, **kwargs) else: message = dumps({'message': "Permission or Token is invalid!"}) return Response(message, status=401, mimetype='application/json') return decorated def admin_check(): token = None if 'liftnec-token' in request.headers: token = request.headers['liftnec-token'] if not token: message = dumps({'message': "Token is missing!"}) return Response(message, status=401, mimetype='application/json') if token == "liftnec-admin": session["current_user_id"] = "admin" session["current_org_id"] = "admin" return True else: return False api.add_resource(auth_router, '/login', endpoint='api-auth', methods=['GET', 'POST'])
from bson import json_util from flask_restful import Resource, Api, reqparse, abort from common.Util import Util from resources import app, api, mongo class UsersCollection(Resource): def get(self): query = mongo.db.users.find() list = [json_util.dumps(doc, default=json_util.default) for doc in query] return {'List': list} def post(self): usernameparser = reqparse.RequestParser(trim=True) usernameparser.add_argument('username', type=str, required=True) usernameparser.add_argument('firstname', type=str) usernameparser.add_argument('lastname', type=str) args = usernameparser.parse_args(strict=True) userid = mongo.db.users.insert(args) return '', 201 api.add_resource(UsersCollection, '/users')
from resources import api, app from resources.Authentication import Authentication from resources.QuizResource import QuizResource from resources.UserServices import UserServices from resources.ContactsResource import ContactsServices from resources.PublicationServices import PublicationServices from resources.ParticipationServices import ParticipationServices api.add_resource(Authentication, '/authenticate/', endpoint='authenticate') api.add_resource(UserServices, '/users/', '/users/<login>', endpoint='user') api.add_resource(QuizResource, "/quiz/", "/quiz/<quiz_id>", "/quiz/<quiz_id>/<question_id>", endpoint="quiz") api.add_resource(ContactsServices, "/contacts/", "/contacts/<group_name>", "/contacts/<group_name>/id/<contact_id>", endpoint="contact") api.add_resource(PublicationServices, "/publication/<quiz_id>/", "/publication/<quiz_id>/<contact_group>/", endpoint="publication") api.add_resource(ParticipationServices, "/participation/<pub_hash>/", endpoint="participation") if __name__ == '__main__': app.run(host="0.0.0.0", port=8080, debug=True)
from resources import api from .analysis_item.routes import route_analysisitem from .analysis_category.routes import route_analysiscategory from .analysis_settings.routes import route_analysissettings from .stock.routes import route_stock from .stock_action.routes import route_stockaction from .account.routers import route_account from .contact.routers import route_contact from .quote.routers import route_quote from .project import route_project from .reports import route_reports from .parity import route_parity from .analysis_line_items import route_recalculatelineitems # Parity Route api.add_resource(route_parity, '/api/v1/parity', methods=['GET']) # Reports Route api.add_resource(route_reports, '/api/v1/reports/<action_name>', methods=['GET']) # Analysis Module api.add_resource(route_analysisitem, '/api/v1/analysis-item', '/api/v1/analysis-item/<db_id>', endpoint='api_analysis-item', methods=['GET', 'POST', 'PUT', 'DELETE']) api.add_resource(route_analysiscategory, '/api/v1/analysis-category', '/api/v1/analysis-category/<db_id>', endpoint='api_analysis-category', methods=['GET', 'POST', 'PUT', 'DELETE'])
retUser = self.jobs.update(mongoid, putRequestArgs) return SoftRestResponse.single_item(item_id=str(retUser.id), item=retUser.to_mongo(), document_name='User', created=False) except DoesNotExist as e: return SoftRestResponse.error(message='RECORD_NOT_FOUND', detail=e.args, code=404) except Exception as e: return SoftRestResponse.error(message='SERVER_ERROR_PUT', detail=e.args, code=500) @token_required def delete(self, mongoid): app.logger.debug("***{} fired as DELETE request with id:{}".format( self.__class__.__name__, mongoid)) return self.abstract.delete(db_id=mongoid) # """ # *** Restful Api register for this module *** # """ api.add_resource(user_router, '/api/v1/user', '/api/v1/user/<mongoid>', endpoint='api-users', methods=['GET', 'POST', 'PUT', 'DELETE'])
return Message.objects(id=mongoid).first().to_json(), 201 else: request_parser = GetAllRequestParser(Message, getRequestArgs, None, None) # parse arguments and return result return request_parser.run() @login_required def post(self): app.logger.debug( ("***{} fired as POST request").format(self.__class__.__name__)) try: post_request_args = postArgs().parse_args() app.logger.debug("****(post_request_args['data']" + str(post_request_args['data'])) message = self.jobs.create(post_request_args['data']) app.logger.debug("*** damage " + str(message.to_mongo())) return dumps(loads(message.to_json())), 201 except Exception as e: app.logger.error(("***{} post method occurred an error").format( self.__class__.__name__)) app.logger.exception(e.args) return e.args, 500 app.logger.debug("*** RouteCompany api") api.add_resource(RouteMessage, '/api/v1/message/', '/api/v1/message/<mongoid>', endpoint='message', methods=['GET', 'POST', 'PUT', 'DELETE'])
row_value = row["value"] create_at = "{}-{:02d}-{:02d}T{}:00+00:00Z".format( row_year, row_month, row_day, row_time_start) feature["properties"]["create_at"] = create_at feature["properties"]["city name"] = row_lga feature["properties"]["twitter count"] = row_value result["features"].append(feature) resp = jsonify(result) resp.status_code = 200 return resp api.add_resource(TwitterMap, "/twittermap", endpoint='twittermap') # **************************************************************************** # scenario 1 starts # **************************************************************************** class Scenario1(Resource): def get(self): """ curl -X GET 127.0.0.1:5000/scenario1?lga=Greater_Adelaide,Greater_Melbourne,Greater_Brisbane,Greater_Sydney&weekday=1,2,3&daytime_start=0&daytime_end=24&age_group=0,1,2,17 :parameter: lga: [Greater_Adelaide,Greater_Melbourne,Greater_Brisbane,Greater_Sydney] :parameter: weekday: 0-6 monday to sunday :parameter: daytime_start 0-24
from resources import api, app from resources.Authentication import Authentication from resources.QuizResource import QuizResource from resources.UserServices import UserServices from resources.ContactsResource import ContactsServices from resources.PublicationServices import PublicationServices from resources.ParticipationServices import ParticipationServices api.add_resource(Authentication, '/authenticate/', endpoint='authenticate') api.add_resource(UserServices, '/users/', '/users/<login>', endpoint='user') api.add_resource(QuizResource, "/quiz/", "/quiz/<quiz_id>", "/quiz/<quiz_id>/<question_id>", endpoint="quiz") api.add_resource(ContactsServices, "/contacts/", "/contacts/<group_name>", "/contacts/<group_name>/id/<contact_id>", endpoint="contact") api.add_resource(PublicationServices, "/publication/<quiz_id>/", "/publication/<quiz_id>/<contact_group>/", endpoint="publication") api.add_resource(ParticipationServices, "/participation/<pub_hash>/", endpoint="participation") if __name__ == '__main__': app.run(host="0.0.0.0", port=8080, debug=True)
# -*- coding: utf-8 -*- # !/usr/bin/env python from resources import api from resources.hello import HelloWorld api.add_resource(HelloWorld, '/v1/hello')
del junk["_id"] return render_template('junk/single.html', objectId=objectId, junk=junk) @app.route('/junk/partials/<path:path>') def partials(path): print path return render_template(os.path.join("junk", os.path.join('partials',path+".html"))) @app.route('/junk/<ObjectId:objectId>/<path:path>') def single_junk(objectId, path): junk=mongo.db.junks.find_one_or_404({"_id": objectId}) del junk["_id"] return render_template(os.path.join("junk",os.path.join('partials',path+".html")), objectId=objectId, junk=junk) # API api.add_resource(JunkList, '/api/junks') api.add_resource(Junk, '/api/junk/<ObjectId:junk_id>') @app.route('/api/junk/<ObjectId:objectId>/dna') def get_junk_dna(objectId): junk=mongo.db.junks.find_one_or_404({"_id": objectId}) return jsonify({"dna":junk["dna"]}) @app.route('/api/junk/<ObjectId:objectId>/molecule') def get_junk_molecule(objectId): junk=mongo.db.junks.find_one_or_404({"_id": objectId}) return jsonify({"molecule":junk["molecule"]}) # data @app.route('/data/molecules/<path:path>') def get_molecule_file(path):
return e.args, 500 @login_required def get(self, mongoid=None): getRequestArgs = getArgs().parse_args() if mongoid: return Photo.objects(id=mongoid).first().to_json(), 201 else: request_parser = GetAllRequestParser(Photo, getRequestArgs, None, None) # parse arguments and return result return request_parser.run() @login_required def delete(self, mongoid=None): if mongoid: result = self.jobs.delete(mongoid) if result: return result, 201 else: return result, 500 else: return False, 500 app.logger.debug("*** RoutePhoto api") api.add_resource(RoutePhoto, '/api/v1/photo/', '/api/v1/photo/<mongoid>', endpoint='photo', methods=['GET', 'POST', 'PUT', 'DELETE'])
@token_required def post(self): app.logger.debug("***{} fired as POST request".format( self.__class__.__name__)) return self.abstract.post() @token_required def put(self, mongoid): app.logger.debug("***{} fired as PUT request with id:{}".format( self.__class__.__name__, mongoid)) return self.abstract.put(mongoid=mongoid) @token_required def delete(self, mongoid): app.logger.debug("***{} fired as DELETE request with id:{}".format( self.__class__.__name__, mongoid)) return self.abstract.delete(db_id=mongoid) # """ # *** Restful Api register for this module *** # # """ api.add_resource(RoutePermission, '/api/v1/permission', '/api/v1/permission/<mongoid>', endpoint='api-permission', methods=['GET', 'POST', 'PUT', 'DELETE'])
class RouteNotificationBulk(Resource): @login_required def get(self) -> object: app.logger.debug("***messageBULK fired as get request") return None @login_required def post(self): app.logger.debug("***messageBULK fired as post request") try: #result = mongo.db.message.update_many({"reads_by": {"$ne": current_user.id}}, # {"$push": {"reads_by":current_user.id }}) result = Notification.objects( reads_by__nin=str(current_user.userid)).update( push__reads_by=str(current_user.userid)) app.logger.debug("***message update result : " + str(result)) return True, 201 except Exception as e: app.logger.error("***message PUT method occurred an error") app.logger.exception(e.args) return e.args, 500 api.add_resource(RouteNotification, '/api/v1/notification/', '/api/v1/notification/<mongoId>', endpoint='module/message/', methods=['GET', 'POST', 'PUT']) api.add_resource(RouteNotificationBulk, '/api/v1/notification-bulk/')
user = mongo.db.users.find_one_or_404({"username": username}) return json_util.dumps(user, default=json_util.default) def put(self, username): user = mongo.db.users.find_one_or_404({"username": username}) usernameparser = reqparse.RequestParser(trim=True) usernameparser.add_argument('username', type=str) usernameparser.add_argument('firstname', type=str) usernameparser.add_argument('lastname', type=str) args = usernameparser.parse_args(strict=True) if args['firstname']: user['firstname'] = args['firstname'] if args['lastname']: user['lastname'] = args['lastname'] mongo.db.users.update({"username": username}, user) return '', 204 def delete(self, username): mongo.db.users.find_one_or_404({"username": username}) mongo.db.users.remove({"username": username}) return '', 204 api.add_resource(UserDetail, '/users/<string:username>')