def on_message(client, userdata, msg): Engine = database.Engine(DB_PATH) Connection = Engine.connect() Connection.create_device("abcd", msg.topic, msg.payload) Connection.close() print("Received message, topic:" + msg.topic + " payload:" + str(msg.payload))
ATOM_THREAD_PROFILE = "https://tools.ietf.org/html/rfc4685" # Fill these in APIARY_PROFILES_URL = "http://docs.pwp2017exercise318.apiary.io/#/reference/profiles/" APIARY_RELS_URL = "http://docs.pwp2017exercise318.apiary.io/#/reference/link-relations/" USER_SCHEMA_URL = "/forum/schema/user/" LINK_RELATIONS_URL = "/forum/link-relations/" #Define the application and the api app = Flask(__name__, static_folder="static", static_url_path="/.") app.debug = True # Set the database Engine. In order to modify the database file (e.g. for # testing) provide the database path app.config to modify the #database to be used (for instance for testing) app.config.update({"Engine": database.Engine()}) #Start the RESTful API. api = Api(app) # These two classes below are how we make producing the resource representation # JSON documents manageable and resilient to errors. As noted, our mediatype is # Mason. Similar solutions can easily be implemented for other mediatypes. class MasonObject(dict): """ A convenience class for managing dictionaries that represent Mason objects. It provides nice shorthands for inserting some of the more elements into the object but mostly is just a parent for the much more useful subclass defined next. This class is generic in the sense that it does not contain any application specific implementation details.
#Constants for hypermedia formats and profiles COLLECTIONJSON = "application/vnd.collection+json" HAL = "application/hal+json" FORUM_USER_PROFILE = "/profiles/user-profile" FORUM_ORDER_PROFILE = "/profiles/order-profile" ATOM_THREAD_PROFILE = "https://tools.ietf.org/html/rfc4685" APIARY_PROFILES_URL = "http://docs.pwpforumappcomplete.apiary.io/#reference/profiles/" #Define the application and the api app = Flask(__name__) app.debug = True # Set the database Engine. In order to modify the database file (e.g. for # testing) provide the database path app.config to modify the #database to be used (for instance for testing) app.config.update({'Engine': database.Engine()}) #Start the RESTful API. api = Api(app) #Add support for cors CORS(app) #ERROR HANDLERS #TODO: Modify this accordding # http://soabits.blogspot.no/2013/05/error-handling-considerations-and-best.html # I should define a profile for the error. def create_error_response(status_code, title, message=None): ''' Creates a: py: class:`flask.Response` instance when sending back an HTTP error response : param integer status_code: The HTTP status code of the response : param str title: A short description of the problem