Add login endpoint
parent
7558ab4737
commit
0a0f18fd66
|
@ -30,6 +30,7 @@ pip-log.txt
|
|||
venv
|
||||
*.pyc
|
||||
build
|
||||
env
|
||||
|
||||
# Instance dir
|
||||
instance/
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# App initialization
|
||||
from flask_api import FlaskAPI
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_bcrypt import Bcrypt
|
||||
|
||||
app = FlaskAPI(__name__, instance_relative_config=True)
|
||||
app.config.from_object('config')
|
||||
app.config.from_pyfile('config.py', silent=True)
|
||||
db = SQLAlchemy(app)
|
||||
bcrypt = Bcrypt(app)
|
||||
|
||||
|
||||
def setup_blueprints(app):
|
||||
|
|
|
@ -1,20 +1,70 @@
|
|||
from app import db
|
||||
from flask import request, jsonify, abort
|
||||
from .models import Account, Role
|
||||
from app import bcrypt
|
||||
from flask import request, jsonify
|
||||
from .models import Account
|
||||
|
||||
|
||||
def initialize_routes(accounts):
|
||||
@accounts.route("/", methods=['POST'])
|
||||
def create():
|
||||
def create_account():
|
||||
print(request.data)
|
||||
user = request.data.get('user')
|
||||
acct = Account(user.get('username'),
|
||||
user.get('password'),
|
||||
user.get('email'),
|
||||
2)
|
||||
acct.save()
|
||||
if not Account.exists_with_any_of(
|
||||
username=user.get('username'), email=user.get('email')):
|
||||
password_hash = bcrypt.generate_password_hash(
|
||||
user.get('password')
|
||||
).decode('utf-8')
|
||||
acct = Account(user.get('username'),
|
||||
password_hash,
|
||||
user.get('email'))
|
||||
acct.save()
|
||||
response = jsonify({
|
||||
'status': 'success',
|
||||
'message': 'Success!'
|
||||
})
|
||||
response.status_code = 200
|
||||
return response
|
||||
else:
|
||||
response = jsonify({
|
||||
'status': 'error',
|
||||
'message': 'User already exists!'
|
||||
})
|
||||
response.status_code = 422
|
||||
return response
|
||||
|
||||
@accounts.route("/token", methods=['POST'])
|
||||
def create_token():
|
||||
print(request.data)
|
||||
user = request.data.get('user')
|
||||
if not user:
|
||||
response = jsonify({
|
||||
'status': 'error',
|
||||
'message': 'Invalid request'
|
||||
})
|
||||
response.status_code = 400
|
||||
return response
|
||||
|
||||
if not Account.exists(username=user.get('username')):
|
||||
response = jsonify({
|
||||
'status': 'error',
|
||||
'message': 'Invalid credentials'
|
||||
})
|
||||
response.status_code = 422
|
||||
return response
|
||||
|
||||
account = Account.get(username=user.get('username'))
|
||||
if not bcrypt.check_password_hash(
|
||||
account.password, user.get('password')):
|
||||
response = jsonify({
|
||||
'status': 'error',
|
||||
'message': 'Invalid credentials'
|
||||
})
|
||||
response.status_code = 422
|
||||
return response
|
||||
|
||||
response = jsonify({
|
||||
'message':'Success!'
|
||||
'status': 'success',
|
||||
'message': 'Successfully logged in',
|
||||
'token': account.create_auth_token()
|
||||
})
|
||||
response.status_code = 200
|
||||
return response
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from app import db
|
||||
import jwt
|
||||
import datetime
|
||||
from app import db, app
|
||||
|
||||
|
||||
class Account(db.Model):
|
||||
|
@ -11,7 +13,7 @@ class Account(db.Model):
|
|||
role_id = db.Column(db.Integer, db.ForeignKey("roles.id"))
|
||||
role = db.relationship("Role", foreign_keys=[role_id])
|
||||
|
||||
def __init__(self, username, password, email, role):
|
||||
def __init__(self, username, password, email, role=2):
|
||||
self.username = str(username)
|
||||
self.password = str(password)
|
||||
self.email = str(email)
|
||||
|
@ -21,16 +23,60 @@ class Account(db.Model):
|
|||
self.role_id = int(role)
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
Stores current user to database
|
||||
This may raise errors
|
||||
"""
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
|
||||
@staticmethod
|
||||
def exists_with_any_of(**kwargs):
|
||||
"""
|
||||
Checks if user with any of the given arguments exists
|
||||
"""
|
||||
for key, value in kwargs.items():
|
||||
args = {key: value}
|
||||
if Account.query.filter_by(**args).first():
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def exists(**kwargs):
|
||||
"""
|
||||
Checks if user with all of the given arguments exists
|
||||
"""
|
||||
if Account.query.filter_by(**kwargs).first():
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_all():
|
||||
return Account.query.all()
|
||||
|
||||
@staticmethod
|
||||
def get(accId):
|
||||
return Account.query.filter_by(id = accId)
|
||||
def get(**kwargs):
|
||||
return Account.query.filter_by(**kwargs).first()
|
||||
|
||||
def create_auth_token(self):
|
||||
"""
|
||||
Generates the Auth Token
|
||||
:return: string
|
||||
"""
|
||||
try:
|
||||
current_time = datetime.datetime.utcnow()
|
||||
payload = {
|
||||
'exp': current_time + datetime.timedelta(days=0, hours=1),
|
||||
'iat': current_time,
|
||||
'sub': self.id
|
||||
}
|
||||
return jwt.encode(
|
||||
payload,
|
||||
app.config.get('SECRET_KEY'),
|
||||
algorithm='HS256'
|
||||
).decode('utf-8')
|
||||
except Exception as e:
|
||||
return e
|
||||
|
||||
def __repr__(self):
|
||||
return '<Account (name=%s, role=%s)>' % self.username, self.role
|
||||
|
@ -55,7 +101,7 @@ class Role(db.Model):
|
|||
|
||||
@staticmethod
|
||||
def get(roleId):
|
||||
return Role.query.filter_by(id = accId)
|
||||
return Role.query.filter_by(id=roleId)
|
||||
|
||||
def __repr__(self):
|
||||
return '<Role %s>' % self.name
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import os
|
||||
|
||||
# App configuration
|
||||
DEBUG = False
|
||||
|
||||
# Define the application directory
|
||||
import os
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
# Define the database - we are working with
|
||||
SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']
|
||||
|
@ -20,11 +21,11 @@ THREADS_PER_PAGE = 2
|
|||
CSRF_ENABLED = True
|
||||
|
||||
# Use a secure, unique and absolutely secret key for
|
||||
# signing the data.
|
||||
# signing the data.
|
||||
CSRF_SESSION_KEY = "secret"
|
||||
|
||||
# Secret key for signing cookies
|
||||
SECRET_KEY = "secret"
|
||||
SECRET_KEY = "?['Z(Z\x83Y \x06T\x12\x96<\xff\x12\xe0\x1b\xd1J\xe0\xd9ld"
|
||||
|
||||
# MQTT configuration
|
||||
MQTT_BROKER_URL = 'broker.hivemq.com'
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/Python
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/include/python3.6m
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/__future__.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_bootlocale.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_collections_abc.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_dummy_thread.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_weakrefset.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/abc.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/base64.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/bisect.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/copy.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/copyreg.py
|
|
@ -1,101 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
import warnings
|
||||
import imp
|
||||
import opcode # opcode is not a virtualenv module, so we can use it to find the stdlib
|
||||
# Important! To work on pypy, this must be a module that resides in the
|
||||
# lib-python/modified-x.y.z directory
|
||||
|
||||
dirname = os.path.dirname
|
||||
|
||||
distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
|
||||
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
|
||||
warnings.warn(
|
||||
"The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
|
||||
else:
|
||||
__path__.insert(0, distutils_path)
|
||||
real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ('', '', imp.PKG_DIRECTORY))
|
||||
# Copy the relevant attributes
|
||||
try:
|
||||
__revision__ = real_distutils.__revision__
|
||||
except AttributeError:
|
||||
pass
|
||||
__version__ = real_distutils.__version__
|
||||
|
||||
from distutils import dist, sysconfig
|
||||
|
||||
try:
|
||||
basestring
|
||||
except NameError:
|
||||
basestring = str
|
||||
|
||||
## patch build_ext (distutils doesn't know how to get the libs directory
|
||||
## path on windows - it hardcodes the paths around the patched sys.prefix)
|
||||
|
||||
if sys.platform == 'win32':
|
||||
from distutils.command.build_ext import build_ext as old_build_ext
|
||||
class build_ext(old_build_ext):
|
||||
def finalize_options (self):
|
||||
if self.library_dirs is None:
|
||||
self.library_dirs = []
|
||||
elif isinstance(self.library_dirs, basestring):
|
||||
self.library_dirs = self.library_dirs.split(os.pathsep)
|
||||
|
||||
self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
|
||||
old_build_ext.finalize_options(self)
|
||||
|
||||
from distutils.command import build_ext as build_ext_module
|
||||
build_ext_module.build_ext = build_ext
|
||||
|
||||
## distutils.dist patches:
|
||||
|
||||
old_find_config_files = dist.Distribution.find_config_files
|
||||
def find_config_files(self):
|
||||
found = old_find_config_files(self)
|
||||
system_distutils = os.path.join(distutils_path, 'distutils.cfg')
|
||||
#if os.path.exists(system_distutils):
|
||||
# found.insert(0, system_distutils)
|
||||
# What to call the per-user config file
|
||||
if os.name == 'posix':
|
||||
user_filename = ".pydistutils.cfg"
|
||||
else:
|
||||
user_filename = "pydistutils.cfg"
|
||||
user_filename = os.path.join(sys.prefix, user_filename)
|
||||
if os.path.isfile(user_filename):
|
||||
for item in list(found):
|
||||
if item.endswith('pydistutils.cfg'):
|
||||
found.remove(item)
|
||||
found.append(user_filename)
|
||||
return found
|
||||
dist.Distribution.find_config_files = find_config_files
|
||||
|
||||
## distutils.sysconfig patches:
|
||||
|
||||
old_get_python_inc = sysconfig.get_python_inc
|
||||
def sysconfig_get_python_inc(plat_specific=0, prefix=None):
|
||||
if prefix is None:
|
||||
prefix = sys.real_prefix
|
||||
return old_get_python_inc(plat_specific, prefix)
|
||||
sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__
|
||||
sysconfig.get_python_inc = sysconfig_get_python_inc
|
||||
|
||||
old_get_python_lib = sysconfig.get_python_lib
|
||||
def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
||||
if standard_lib and prefix is None:
|
||||
prefix = sys.real_prefix
|
||||
return old_get_python_lib(plat_specific, standard_lib, prefix)
|
||||
sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__
|
||||
sysconfig.get_python_lib = sysconfig_get_python_lib
|
||||
|
||||
old_get_config_vars = sysconfig.get_config_vars
|
||||
def sysconfig_get_config_vars(*args):
|
||||
real_vars = old_get_config_vars(*args)
|
||||
if sys.platform == 'win32':
|
||||
lib_dir = os.path.join(sys.real_prefix, "libs")
|
||||
if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars:
|
||||
real_vars['LIBDIR'] = lib_dir # asked for all
|
||||
elif isinstance(real_vars, list) and 'LIBDIR' in args:
|
||||
real_vars = real_vars + [lib_dir] # asked for list
|
||||
return real_vars
|
||||
sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__
|
||||
sysconfig.get_config_vars = sysconfig_get_config_vars
|
|
@ -1,6 +0,0 @@
|
|||
# This is a config file local to this virtualenv installation
|
||||
# You may include options that will be used by all distutils commands,
|
||||
# and by easy_install. For instance:
|
||||
#
|
||||
# [easy_install]
|
||||
# find_links = http://mylocalsite
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/enum.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/fnmatch.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/genericpath.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/hashlib.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/heapq.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/hmac.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/io.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/keyword.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/linecache.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/locale.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ntpath.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/operator.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/posixpath.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/reprlib.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/rlcompleter.py
|
|
@ -1 +0,0 @@
|
|||
/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py
|
|
@ -1,46 +0,0 @@
|
|||
Flask
|
||||
-----
|
||||
|
||||
Flask is a microframework for Python based on Werkzeug, Jinja 2 and good
|
||||
intentions. And before you ask: It's BSD licensed!
|
||||
|
||||
Flask is Fun
|
||||
````````````
|
||||
|
||||
Save in a hello.py:
|
||||
|
||||
.. code:: python
|
||||
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
||||
And Easy to Setup
|
||||
`````````````````
|
||||
|
||||
And run it:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ pip install Flask
|
||||
$ python hello.py
|
||||
* Running on http://localhost:5000/
|
||||
|
||||
Ready for production? `Read this first <http://flask.pocoo.org/docs/deploying/>`.
|
||||
|
||||
Links
|
||||
`````
|
||||
|
||||
* `website <http://flask.pocoo.org/>`_
|
||||
* `documentation <http://flask.pocoo.org/docs/>`_
|
||||
* `development version
|
||||
<http://github.com/pallets/flask/zipball/master#egg=Flask-dev>`_
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
pip
|
|
@ -1,33 +0,0 @@
|
|||
Copyright (c) 2015 by Armin Ronacher and contributors. See AUTHORS
|
||||
for more details.
|
||||
|
||||
Some rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms of the software as well
|
||||
as documentation, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* The names of the contributors may not be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
|
||||
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
|
@ -1,75 +0,0 @@
|
|||
Metadata-Version: 2.0
|
||||
Name: Flask
|
||||
Version: 0.12.2
|
||||
Summary: A microframework based on Werkzeug, Jinja2 and good intentions
|
||||
Home-page: http://github.com/pallets/flask/
|
||||
Author: Armin Ronacher
|
||||
Author-email: armin.ronacher@active-4.com
|
||||
License: BSD
|
||||
Platform: any
|
||||
Classifier: Development Status :: 4 - Beta
|
||||
Classifier: Environment :: Web Environment
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: BSD License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 2
|
||||
Classifier: Programming Language :: Python :: 2.6
|
||||
Classifier: Programming Language :: Python :: 2.7
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.3
|
||||
Classifier: Programming Language :: Python :: 3.4
|
||||
Classifier: Programming Language :: Python :: 3.5
|
||||
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Requires-Dist: Jinja2 (>=2.4)
|
||||
Requires-Dist: Werkzeug (>=0.7)
|
||||
Requires-Dist: click (>=2.0)
|
||||
Requires-Dist: itsdangerous (>=0.21)
|
||||
|
||||
Flask
|
||||
-----
|
||||
|
||||
Flask is a microframework for Python based on Werkzeug, Jinja 2 and good
|
||||
intentions. And before you ask: It's BSD licensed!
|
||||
|
||||
Flask is Fun
|
||||
````````````
|
||||
|
||||
Save in a hello.py:
|
||||
|
||||
.. code:: python
|
||||
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
||||
And Easy to Setup
|
||||
`````````````````
|
||||
|
||||
And run it:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ pip install Flask
|
||||
$ python hello.py
|
||||
* Running on http://localhost:5000/
|
||||
|
||||
Ready for production? `Read this first <http://flask.pocoo.org/docs/deploying/>`.
|
||||
|
||||
Links
|
||||
`````
|
||||
|
||||
* `website <http://flask.pocoo.org/>`_
|
||||
* `documentation <http://flask.pocoo.org/docs/>`_
|
||||
* `development version
|
||||
<http://github.com/pallets/flask/zipball/master#egg=Flask-dev>`_
|
||||
|
||||
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
Flask-0.12.2.dist-info/DESCRIPTION.rst,sha256=DmJm8IBlBjl3wkm0Ly23jYvWbvK_mCuE5oUseYCijbI,810
|
||||
Flask-0.12.2.dist-info/LICENSE.txt,sha256=hLgKluMRHSnxG-L0EmrqjmKgG5cHlff6pIh3rCNINeI,1582
|
||||
Flask-0.12.2.dist-info/METADATA,sha256=OgSkJQ_kmrz4qEkS-OzYtL75uZmXAThymkOcGR4kXRQ,1948
|
||||
Flask-0.12.2.dist-info/RECORD,,
|
||||
Flask-0.12.2.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
|
||||
Flask-0.12.2.dist-info/entry_points.txt,sha256=jzk2Wy2h30uEcqqzd4CVnlzsMXB-vaD5GXjuPMXmTmI,60
|
||||
Flask-0.12.2.dist-info/metadata.json,sha256=By8kZ1vY9lLEAGnRiWNBhudqKvLPo0HkZVXTYECyPKk,1389
|
||||
Flask-0.12.2.dist-info/top_level.txt,sha256=dvi65F6AeGWVU0TBpYiC04yM60-FX1gJFkK31IKQr5c,6
|
||||
flask/__init__.py,sha256=sHdK1v6WRbVmCN0fEv990EE7rOT2UlamQkSof2d0Dt0,1673
|
||||
flask/__main__.py,sha256=cldbNi5zpjE68XzIWI8uYHNWwBHHVJmwtlXWk6P4CO4,291
|
||||
flask/_compat.py,sha256=VlfjUuLjufsTHJIjr_ZsnnOesSbAXIslBBgRe5tfOok,2802
|
||||
flask/app.py,sha256=6DPjtb5jUJWgL5fXksG5boA49EB3l-k9pWyftitbNNk,83169
|
||||
flask/blueprints.py,sha256=6HVasMcPcaq7tk36kCrgX4bnhTkky4G5WIWCyyJL8HY,16872
|
||||
flask/cli.py,sha256=2NXEdCOu5-4ymklxX4Lf6bjb-89I4VHYeP6xScR3i8E,18328
|
||||
flask/config.py,sha256=Ym5Jenyu6zAZ1fdVLeKekY9-EsKmq8183qnRgauwCMY,9905
|
||||
flask/ctx.py,sha256=UPA0YwoIlHP0txOGanC9lQLSGv6eCqV5Fmw2cVJRmgQ,14739
|
||||
flask/debughelpers.py,sha256=z-uQavKIymOZl0WQDLXsnacA00ERIlCx3S3Tnb_OYsE,6024
|
||||
flask/exthook.py,sha256=SvXs5jwpcOjogwJ7SNquiWTxowoN1-MHFoqAejWnk2o,5762
|
||||
flask/globals.py,sha256=I3m_4RssLhWW1R11zuEI8oFryHUHX3NQwjMkGXOZzg8,1645
|
||||
flask/helpers.py,sha256=KrsQ2Yo3lOVHvBTgQCLvpubgmTOpQdTTyiCOOYlwDuQ,38452
|
||||
flask/json.py,sha256=1zPM-NPLiWoOfGd0P14FxnEkeKtjtUZxMC9pyYyDBYI,9183
|
||||
flask/logging.py,sha256=UG-77jPkRClk9w1B-_ArjjXPuj9AmZz9mG0IRGvptW0,2751
|
||||
flask/sessions.py,sha256=QBKXVYKJ-HKbx9m6Yb5yan_EPq84a5yevVLgAzNKFQY,14394
|
||||
flask/signals.py,sha256=MfZk5qTRj_R_O3aGYlTEnx2g3SvlZncz8Ii73eKK59g,2209
|
||||
flask/templating.py,sha256=u7FbN6j56H_q6CrdJJyJ6gZtqaMa0vh1_GP12gEHRQQ,4912
|
||||
flask/testing.py,sha256=II8EO_NjOT1LvL8Hh_SdIFL_BdlwVPcB9yot5pbltxE,5630
|
||||
flask/views.py,sha256=6OPv7gwu3h14JhqpeeMRWwrxoGHsUr4_nOGSyTRAxAI,5630
|
||||
flask/wrappers.py,sha256=1S_5mmuA1Tlx7D9lXV6xMblrg-PdAauNWahe-henMEE,7612
|
||||
flask/ext/__init__.py,sha256=UEezCApsG4ZJWqwUnX9YmWcNN4OVENgph_9L05n0eOM,842
|
||||
../../../bin/flask,sha256=1ow220Ff1jdiAk6Kq--IP8c1BYJdNqtYXFLTS5ul3yA,266
|
||||
Flask-0.12.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
flask/ext/__pycache__/__init__.cpython-36.pyc,,
|
||||
flask/__pycache__/blueprints.cpython-36.pyc,,
|
||||
flask/__pycache__/logging.cpython-36.pyc,,
|
||||
flask/__pycache__/sessions.cpython-36.pyc,,
|
||||
flask/__pycache__/templating.cpython-36.pyc,,
|
||||
flask/__pycache__/cli.cpython-36.pyc,,
|
||||
flask/__pycache__/config.cpython-36.pyc,,
|
||||
flask/__pycache__/signals.cpython-36.pyc,,
|
||||
flask/__pycache__/testing.cpython-36.pyc,,
|
||||
flask/__pycache__/views.cpython-36.pyc,,
|
||||
flask/__pycache__/ctx.cpython-36.pyc,,
|
||||
flask/__pycache__/app.cpython-36.pyc,,
|
||||
flask/__pycache__/exthook.cpython-36.pyc,,
|
||||
flask/__pycache__/__main__.cpython-36.pyc,,
|
||||
flask/__pycache__/_compat.cpython-36.pyc,,
|
||||
flask/__pycache__/helpers.cpython-36.pyc,,
|
||||
flask/__pycache__/wrappers.cpython-36.pyc,,
|
||||
flask/__pycache__/__init__.cpython-36.pyc,,
|
||||
flask/__pycache__/debughelpers.cpython-36.pyc,,
|
||||
flask/__pycache__/globals.cpython-36.pyc,,
|
||||
flask/__pycache__/json.cpython-36.pyc,,
|
|
@ -1,6 +0,0 @@
|
|||
Wheel-Version: 1.0
|
||||
Generator: bdist_wheel (0.29.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
[console_scripts]
|
||||
flask=flask.cli:main
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"classifiers": ["Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules"], "extensions": {"python.commands": {"wrap_console": {"flask": "flask.cli:main"}}, "python.details": {"contacts": [{"email": "armin.ronacher@active-4.com", "name": "Armin Ronacher", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst", "license": "LICENSE.txt"}, "project_urls": {"Home": "http://github.com/pallets/flask/"}}, "python.exports": {"console_scripts": {"flask": "flask.cli:main"}}}, "extras": [], "generator": "bdist_wheel (0.29.0)", "license": "BSD", "metadata_version": "2.0", "name": "Flask", "platform": "any", "run_requires": [{"requires": ["Jinja2 (>=2.4)", "Werkzeug (>=0.7)", "click (>=2.0)", "itsdangerous (>=0.21)"]}], "summary": "A microframework based on Werkzeug, Jinja2 and good intentions", "version": "0.12.2"}
|
|
@ -1 +0,0 @@
|
|||
flask
|
|
@ -1,173 +0,0 @@
|
|||
# Flask-MQTT
|
||||
|
||||
Flask Extension for the [MQTT protocol][1]. Basically it is a thin wrapper
|
||||
around [paho-mqtt][0] and aimes to simplify MQTT integration in Flask. MQTT is a
|
||||
machine-to-machine "Internet of Things" protocol and was designed for extremely
|
||||
lightweight publish/subscribe messaging transport.
|
||||
|
||||
[![Documentation Status](https://readthedocs.org/projects/flask-mqtt/badge/?version=latest)](http://flask-mqtt.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/Flask-MQTT.svg)](https://badge.fury.io/py/Flask-MQTT) [![Travis CI](https://travis-ci.org/stlehmann/Flask-MQTT.svg?branch=master)](https://travis-ci.org/stlehmann/Flask-MQTT.svg?branch=master)
|
||||
|
||||
Find the documentation on [http://flask-mqtt.readthedocs.io][2].
|
||||
|
||||
## Features
|
||||
|
||||
* configuration via Flask config variables
|
||||
* auto-connect on start of your web application
|
||||
* publish and subscribe messages
|
||||
* use callbacks for certain topics
|
||||
* use one callback for all subscribed topics
|
||||
|
||||
## Installation
|
||||
|
||||
Simply install the package as usual via pip:
|
||||
|
||||
```bash
|
||||
$ pip install flask-mqtt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
from flask_mqtt import Mqtt
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['MQTT_BROKER_URL'] = 'mybroker.com'
|
||||
app.config['MQTT_BROKER_PORT'] = 1883
|
||||
app.config['MQTT_USERNAME'] = 'user'
|
||||
app.config['MQTT_PASSWORD'] = 'secret'
|
||||
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
||||
mqtt = Mqtt(app)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
```
|
||||
|
||||
### Subscribe to a topic
|
||||
|
||||
To subscribe to a topic simply use `mqtt.subscribe()`. To make sure the
|
||||
subscription gets handled correctly on startup place the subscription inside
|
||||
an `on_connect()` callback function.
|
||||
|
||||
```python
|
||||
@mqtt.on_connect()
|
||||
def handle_connect(client, userdata, flags, rc):
|
||||
mqtt.subscribe('home/mytopic')
|
||||
```
|
||||
|
||||
To handle the subscribed messages you can define a handling function by
|
||||
decorating it with `@mqtt.on_message()`.
|
||||
|
||||
```python
|
||||
@mqtt.on_message()
|
||||
def handle_mqtt_message(client, userdata, message):
|
||||
data = dict(
|
||||
topic=message.topic,
|
||||
payload=message.payload.decode()
|
||||
)
|
||||
```
|
||||
|
||||
To unsubscribe do:
|
||||
|
||||
```python
|
||||
mqtt.unsubscribe('home/mytopic')
|
||||
```
|
||||
|
||||
Or if you want to unsubscribe all topics use `unsubscribe_all()`.
|
||||
|
||||
```python
|
||||
mqtt.unsubscribe_all()
|
||||
```
|
||||
|
||||
### Publish
|
||||
|
||||
To publish a message you can use the `publish()` method.
|
||||
|
||||
```python
|
||||
mqtt.publish('home/mytopic', 'this is my message')
|
||||
```
|
||||
|
||||
### Small publish/subscribe MQTT client
|
||||
|
||||
```python
|
||||
"""
|
||||
|
||||
A small Test application to show how to use Flask-MQTT.
|
||||
|
||||
"""
|
||||
|
||||
import eventlet
|
||||
import json
|
||||
from flask import Flask, render_template
|
||||
from flask_mqtt import Mqtt
|
||||
from flask_socketio import SocketIO
|
||||
from flask_bootstrap import Bootstrap
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET'] = 'my secret key'
|
||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||
app.config['MQTT_BROKER_URL'] = 'broker.hivemq.com'
|
||||
app.config['MQTT_BROKER_PORT'] = 1883
|
||||
app.config['MQTT_USERNAME'] = ''
|
||||
app.config['MQTT_PASSWORD'] = ''
|
||||
app.config['MQTT_KEEPALIVE'] = 5
|
||||
app.config['MQTT_TLS_ENABLED'] = False
|
||||
|
||||
# Parameters for SSL enabled
|
||||
# app.config['MQTT_BROKER_PORT'] = 8883
|
||||
# app.config['MQTT_TLS_ENABLED'] = True
|
||||
# app.config['MQTT_TLS_INSECURE'] = True
|
||||
# app.config['MQTT_TLS_CA_CERTS'] = 'ca.crt'
|
||||
|
||||
mqtt = Mqtt(app)
|
||||
socketio = SocketIO(app)
|
||||
bootstrap = Bootstrap(app)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@socketio.on('publish')
|
||||
def handle_publish(json_str):
|
||||
data = json.loads(json_str)
|
||||
mqtt.publish(data['topic'], data['message'])
|
||||
|
||||
|
||||
@socketio.on('subscribe')
|
||||
def handle_subscribe(json_str):
|
||||
data = json.loads(json_str)
|
||||
mqtt.subscribe(data['topic'])
|
||||
|
||||
|
||||
@mqtt.on_message()
|
||||
def handle_mqtt_message(client, userdata, message):
|
||||
data = dict(
|
||||
topic=message.topic,
|
||||
payload=message.payload.decode()
|
||||
)
|
||||
socketio.emit('mqtt_message', data=data)
|
||||
|
||||
|
||||
@mqtt.on_log()
|
||||
def handle_logging(client, userdata, level, buf):
|
||||
print(level, buf)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
socketio.run(app, host='0.0.0.0', port=5000, use_reloader=True, debug=True)
|
||||
|
||||
```
|
||||
|
||||
[0]: https://github.com/eclipse/paho.mqtt.python
|
||||
[1]: http://mqtt.org/
|
||||
[2]: http://flask-mqtt.readthedocs.io/en/latest/
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
pip
|
|
@ -1,194 +0,0 @@
|
|||
Metadata-Version: 2.0
|
||||
Name: Flask-MQTT
|
||||
Version: 1.0.3
|
||||
Summary: Flask extension for the MQTT protocol
|
||||
Home-page: https://github.com/MrLeeh/Flask-MQTT
|
||||
Author: Stefan Lehmann
|
||||
Author-email: stefan.st.lehmann@gmail.com
|
||||
License: MIT
|
||||
Platform: any
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Environment :: Web Environment
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Description-Content-Type: text/markdown
|
||||
Requires-Dist: Flask
|
||||
Requires-Dist: typing
|
||||
Requires-Dist: paho-mqtt
|
||||
|
||||
# Flask-MQTT
|
||||
|
||||
Flask Extension for the [MQTT protocol][1]. Basically it is a thin wrapper
|
||||
around [paho-mqtt][0] and aimes to simplify MQTT integration in Flask. MQTT is a
|
||||
machine-to-machine "Internet of Things" protocol and was designed for extremely
|
||||
lightweight publish/subscribe messaging transport.
|
||||
|
||||
[![Documentation Status](https://readthedocs.org/projects/flask-mqtt/badge/?version=latest)](http://flask-mqtt.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/Flask-MQTT.svg)](https://badge.fury.io/py/Flask-MQTT) [![Travis CI](https://travis-ci.org/stlehmann/Flask-MQTT.svg?branch=master)](https://travis-ci.org/stlehmann/Flask-MQTT.svg?branch=master)
|
||||
|
||||
Find the documentation on [http://flask-mqtt.readthedocs.io][2].
|
||||
|
||||
## Features
|
||||
|
||||
* configuration via Flask config variables
|
||||
* auto-connect on start of your web application
|
||||
* publish and subscribe messages
|
||||
* use callbacks for certain topics
|
||||
* use one callback for all subscribed topics
|
||||
|
||||
## Installation
|
||||
|
||||
Simply install the package as usual via pip:
|
||||
|
||||
```bash
|
||||
$ pip install flask-mqtt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
from flask_mqtt import Mqtt
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['MQTT_BROKER_URL'] = 'mybroker.com'
|
||||
app.config['MQTT_BROKER_PORT'] = 1883
|
||||
app.config['MQTT_USERNAME'] = 'user'
|
||||
app.config['MQTT_PASSWORD'] = 'secret'
|
||||
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
||||
mqtt = Mqtt(app)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
```
|
||||
|
||||
### Subscribe to a topic
|
||||
|
||||
To subscribe to a topic simply use `mqtt.subscribe()`. To make sure the
|
||||
subscription gets handled correctly on startup place the subscription inside
|
||||
an `on_connect()` callback function.
|
||||
|
||||
```python
|
||||
@mqtt.on_connect()
|
||||
def handle_connect(client, userdata, flags, rc):
|
||||
mqtt.subscribe('home/mytopic')
|
||||
```
|
||||
|
||||
To handle the subscribed messages you can define a handling function by
|
||||
decorating it with `@mqtt.on_message()`.
|
||||
|
||||
```python
|
||||
@mqtt.on_message()
|
||||
def handle_mqtt_message(client, userdata, message):
|
||||
data = dict(
|
||||
topic=message.topic,
|
||||
payload=message.payload.decode()
|
||||
)
|
||||
```
|
||||
|
||||
To unsubscribe do:
|
||||
|
||||
```python
|
||||
mqtt.unsubscribe('home/mytopic')
|
||||
```
|
||||
|
||||
Or if you want to unsubscribe all topics use `unsubscribe_all()`.
|
||||
|
||||
```python
|
||||
mqtt.unsubscribe_all()
|
||||
```
|
||||
|
||||
### Publish
|
||||
|
||||
To publish a message you can use the `publish()` method.
|
||||
|
||||
```python
|
||||
mqtt.publish('home/mytopic', 'this is my message')
|
||||
```
|
||||
|
||||
### Small publish/subscribe MQTT client
|
||||
|
||||
```python
|
||||
"""
|
||||
|
||||
A small Test application to show how to use Flask-MQTT.
|
||||
|
||||
"""
|
||||
|
||||
import eventlet
|
||||
import json
|
||||
from flask import Flask, render_template
|
||||
from flask_mqtt import Mqtt
|
||||
from flask_socketio import SocketIO
|
||||
from flask_bootstrap import Bootstrap
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET'] = 'my secret key'
|
||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||
app.config['MQTT_BROKER_URL'] = 'broker.hivemq.com'
|
||||
app.config['MQTT_BROKER_PORT'] = 1883
|
||||
app.config['MQTT_USERNAME'] = ''
|
||||
app.config['MQTT_PASSWORD'] = ''
|
||||
app.config['MQTT_KEEPALIVE'] = 5
|
||||
app.config['MQTT_TLS_ENABLED'] = False
|
||||
|
||||
# Parameters for SSL enabled
|
||||
# app.config['MQTT_BROKER_PORT'] = 8883
|
||||
# app.config['MQTT_TLS_ENABLED'] = True
|
||||
# app.config['MQTT_TLS_INSECURE'] = True
|
||||
# app.config['MQTT_TLS_CA_CERTS'] = 'ca.crt'
|
||||
|
||||
mqtt = Mqtt(app)
|
||||
socketio = SocketIO(app)
|
||||
bootstrap = Bootstrap(app)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@socketio.on('publish')
|
||||
def handle_publish(json_str):
|
||||
data = json.loads(json_str)
|
||||
mqtt.publish(data['topic'], data['message'])
|
||||
|
||||
|
||||
@socketio.on('subscribe')
|
||||
def handle_subscribe(json_str):
|
||||
data = json.loads(json_str)
|
||||
mqtt.subscribe(data['topic'])
|
||||
|
||||
|
||||
@mqtt.on_message()
|
||||
def handle_mqtt_message(client, userdata, message):
|
||||
data = dict(
|
||||
topic=message.topic,
|
||||
payload=message.payload.decode()
|
||||
)
|
||||
socketio.emit('mqtt_message', data=data)
|
||||
|
||||
|
||||
@mqtt.on_log()
|
||||
def handle_logging(client, userdata, level, buf):
|
||||
print(level, buf)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
socketio.run(app, host='0.0.0.0', port=5000, use_reloader=True, debug=True)
|
||||
|
||||
```
|
||||
|
||||
[0]: https://github.com/eclipse/paho.mqtt.python
|
||||
[1]: http://mqtt.org/
|
||||
[2]: http://flask-mqtt.readthedocs.io/en/latest/
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
Flask_MQTT-1.0.3.dist-info/DESCRIPTION.rst,sha256=scdzeVK9SyGF_ZYEjSy07Lvbkx3VKOH5KwRt8oNRx7s,4225
|
||||
Flask_MQTT-1.0.3.dist-info/METADATA,sha256=Sz1g2z9KQFIaAlv4kh2ga0sCeX2GbQb2PAnlyYcKt94,4946
|
||||
Flask_MQTT-1.0.3.dist-info/RECORD,,
|
||||
Flask_MQTT-1.0.3.dist-info/WHEEL,sha256=0mO7-aKM6K9CHeURc5NDYZyLWH5lmR-r4TtPinHxz7Y,93
|
||||
Flask_MQTT-1.0.3.dist-info/metadata.json,sha256=8k4mdFdGj0w-NXl0Q3hK4CX4B0fiqDu-GzTakg9HlQc,901
|
||||
Flask_MQTT-1.0.3.dist-info/top_level.txt,sha256=rDSXoP_WPnaqCmGIyZOn1ieidQ63URSSX4KvlN3HzL8,11
|
||||
flask_mqtt/__init__.py,sha256=SAbjc3stsoQIxpD8IfS__mqSNxgZNhtBo2W4Xn7A2Bg,13391
|
||||
Flask_MQTT-1.0.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
flask_mqtt/__pycache__/__init__.cpython-36.pyc,,
|
|
@ -1,5 +0,0 @@
|
|||
Wheel-Version: 1.0
|
||||
Generator: bdist_wheel (0.30.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: cp36-none-any
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"classifiers": ["Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules"], "description_content_type": "text/markdown", "extensions": {"python.details": {"contacts": [{"email": "stefan.st.lehmann@gmail.com", "name": "Stefan Lehmann", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/MrLeeh/Flask-MQTT"}}}, "extras": [], "generator": "bdist_wheel (0.30.0)", "license": "MIT", "metadata_version": "2.0", "name": "Flask-MQTT", "platform": "any", "run_requires": [{"requires": ["Flask", "paho-mqtt", "typing"]}], "summary": "Flask extension for the MQTT protocol", "version": "1.0.3"}
|
|
@ -1 +0,0 @@
|
|||
flask_mqtt
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
Flask-SQLAlchemy
|
||||
----------------
|
||||
|
||||
Adds SQLAlchemy support to your Flask application.
|
||||
|
||||
Links
|
||||
`````
|
||||
|
||||
* `documentation <http://flask-sqlalchemy.pocoo.org>`_
|
||||
* `development version
|
||||
<http://github.com/mitsuhiko/flask-sqlalchemy/zipball/master#egg=Flask-SQLAlchemy-dev>`_
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
pip
|
|
@ -1,31 +0,0 @@
|
|||
Copyright (c) 2014 by Armin Ronacher.
|
||||
|
||||
Some rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* The names of the contributors may not be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,43 +0,0 @@
|
|||
Metadata-Version: 2.0
|
||||
Name: Flask-SQLAlchemy
|
||||
Version: 2.3.2
|
||||
Summary: Adds SQLAlchemy support to your Flask application
|
||||
Home-page: http://github.com/mitsuhiko/flask-sqlalchemy
|
||||
Author: Phil Howell
|
||||
Author-email: phil@quae.co.uk
|
||||
License: BSD
|
||||
Description-Content-Type: UNKNOWN
|
||||
Platform: any
|
||||
Classifier: Environment :: Web Environment
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: BSD License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 2
|
||||
Classifier: Programming Language :: Python :: 2.6
|
||||
Classifier: Programming Language :: Python :: 2.7
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.3
|
||||
Classifier: Programming Language :: Python :: 3.4
|
||||
Classifier: Programming Language :: Python :: 3.5
|
||||
Classifier: Programming Language :: Python :: 3.6
|
||||
Requires-Dist: Flask (>=0.10)
|
||||
Requires-Dist: SQLAlchemy (>=0.8.0)
|
||||
|
||||
|
||||
Flask-SQLAlchemy
|
||||
----------------
|
||||
|
||||
Adds SQLAlchemy support to your Flask application.
|
||||
|
||||
Links
|
||||
`````
|
||||
|
||||
* `documentation <http://flask-sqlalchemy.pocoo.org>`_
|
||||
* `development version
|
||||
<http://github.com/mitsuhiko/flask-sqlalchemy/zipball/master#egg=Flask-SQLAlchemy-dev>`_
|
||||
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
Flask_SQLAlchemy-2.3.2.dist-info/DESCRIPTION.rst,sha256=Mp4bpckSjf082xflOARFwzWLTnUszq7JxcY0dR9vD2w,273
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/LICENSE.txt,sha256=2smrI3hNiP6c5TcX0fa6fqODgsdJVLC166X0kVxei9A,1457
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/METADATA,sha256=iDXuOIujwz5MXBrH-I4WsW7kLKsY07feI7hggFHFfEk,1384
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/RECORD,,
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/WHEEL,sha256=kdsN-5OJAZIiHN-iO4Rhl82KyS0bDWf4uBwMbkNafr8,110
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/metadata.json,sha256=VOw756wP14azHrBwNxHIfbYkK4DkEPrCaV6Kf0VO36E,1257
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/top_level.txt,sha256=w2K4fNNoTh4HItoFfz2FRQShSeLcvHYrzU_sZov21QU,17
|
||||
flask_sqlalchemy/__init__.py,sha256=0ZyibSbbC_Q1x8Kemp_2s2-NCowd_-CRvLyE1dPfnvw,35991
|
||||
flask_sqlalchemy/_compat.py,sha256=6rFcZZ3kxvyeJUC_FyB62mG1saNU8iQthzWHLDcKPVE,1057
|
||||
flask_sqlalchemy/model.py,sha256=7CTvGxxKmLscwcwq9mVT5ny_w301QZvTVjSqMoMx6DI,4974
|
||||
Flask_SQLAlchemy-2.3.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
flask_sqlalchemy/__pycache__/model.cpython-36.pyc,,
|
||||
flask_sqlalchemy/__pycache__/_compat.cpython-36.pyc,,
|
||||
flask_sqlalchemy/__pycache__/__init__.cpython-36.pyc,,
|
|
@ -1,6 +0,0 @@
|
|||
Wheel-Version: 1.0
|
||||
Generator: bdist_wheel (0.30.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"classifiers": ["Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6"], "description_content_type": "UNKNOWN", "extensions": {"python.details": {"contacts": [{"email": "phil@quae.co.uk", "name": "Phil Howell", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst", "license": "LICENSE.txt"}, "project_urls": {"Home": "http://github.com/mitsuhiko/flask-sqlalchemy"}}}, "extras": [], "generator": "bdist_wheel (0.30.0)", "license": "BSD", "metadata_version": "2.0", "name": "Flask-SQLAlchemy", "platform": "any", "run_requires": [{"requires": ["Flask (>=0.10)", "SQLAlchemy (>=0.8.0)"]}], "summary": "Adds SQLAlchemy support to your Flask application", "version": "2.3.2"}
|
|
@ -1 +0,0 @@
|
|||
flask_sqlalchemy
|
|
@ -1,37 +0,0 @@
|
|||
|
||||
Jinja2
|
||||
~~~~~~
|
||||
|
||||
Jinja2 is a template engine written in pure Python. It provides a
|
||||
`Django`_ inspired non-XML syntax but supports inline expressions and
|
||||
an optional `sandboxed`_ environment.
|
||||
|
||||
Nutshell
|
||||
--------
|
||||
|
||||
Here a small example of a Jinja template::
|
||||
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Memberlist{% endblock %}
|
||||
{% block content %}
|
||||
<ul>
|
||||
{% for user in users %}
|
||||
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
Philosophy
|
||||
----------
|
||||
|
||||
Application logic is for the controller but don't try to make the life
|
||||
for the template designer too hard by giving him too few functionality.
|
||||
|
||||
For more informations visit the new `Jinja2 webpage`_ and `documentation`_.
|
||||
|
||||
.. _sandboxed: https://en.wikipedia.org/wiki/Sandbox_(computer_security)
|
||||
.. _Django: https://www.djangoproject.com/
|
||||
.. _Jinja2 webpage: http://jinja.pocoo.org/
|
||||
.. _documentation: http://jinja.pocoo.org/2/documentation/
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
pip
|
|
@ -1,31 +0,0 @@
|
|||
Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details.
|
||||
|
||||
Some rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* The names of the contributors may not be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,68 +0,0 @@
|
|||
Metadata-Version: 2.0
|
||||
Name: Jinja2
|
||||
Version: 2.10
|
||||
Summary: A small but fast and easy to use stand-alone template engine written in pure python.
|
||||
Home-page: http://jinja.pocoo.org/
|
||||
Author: Armin Ronacher
|
||||
Author-email: armin.ronacher@active-4.com
|
||||
License: BSD
|
||||
Description-Content-Type: UNKNOWN
|
||||
Platform: UNKNOWN
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Environment :: Web Environment
|
||||