Skip to content
Snippets Groups Projects
Commit d419fc72 authored by souvik's avatar souvik
Browse files

Initial Commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 509 additions and 0 deletions
.DS_Store 0 → 100644
File added
.travis.yaml
.swagger-codegen-ignore
README.md
tox.ini
git_push.sh
test-requirements.txt
setup.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
2.4.24
\ No newline at end of file
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
#- "3.5-dev" # 3.5 development branch
#- "nightly" # points to the latest development branch e.g. 3.6-dev
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: nosetests
FROM python:3-alpine to FROM amancevice/pandas:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
EXPOSE 8080
ENTRYPOINT ["python3"]
CMD ["-m", "swagger_server"]
\ No newline at end of file
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled Flask server.
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
## Requirements
Python 3.5.2+
## Usage
To run the server, please execute the following from the root directory:
```
pip3 install -r requirements.txt
python3 -m swagger_server
```
and open your browser to here:
```
http://localhost:8080/v2/ui/
```
Your Swagger definition lives here:
```
http://localhost:8080/v2/swagger.json
```
To launch the integration tests, use tox:
```
sudo pip install tox
tox
```
## Running with Docker
To run the server on a Docker container, please execute the following from the root directory:
```bash
# building the image
docker build -t swagger_server .
# starting up a container
docker run -p 8080:8080 swagger_server
```
\ No newline at end of file
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
git_user_id=$1
git_repo_id=$2
release_note=$3
if [ "$git_user_id" = "" ]; then
git_user_id=""
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id=""
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note=""
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'
setup.py 0 → 100644
# coding: utf-8
import sys
from setuptools import setup, find_packages
NAME = "swagger_server"
VERSION = "1.0.0"
# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
REQUIRES = ["connexion"]
setup(
name=NAME,
version=VERSION,
description="Swagger IoT data",
author_email="poojara@ut.ee",
url="",
keywords=["Swagger", "Swagger IoT data"],
install_requires=REQUIRES,
packages=find_packages(),
package_data={'': ['swagger/swagger.yaml']},
include_package_data=True,
entry_points={
'console_scripts': ['swagger_server=swagger_server.__main__:main']},
long_description="""\
This is documentation for Python Flask micro-service endpoints
"""
)
File added
#!/usr/bin/env python3
import connexion
from swagger_server import encoder
from flask_cors import CORS
def main():
app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = encoder.JSONEncoder
CORS(app.app)
app.add_api('swagger.yaml', arguments={'title': 'Swagger IoT data'})
app.run(port=8080)
if __name__ == '__main__':
main()
\ No newline at end of file
import connexion
import six
from flask import jsonify
from swagger_server import util
import json
import pandas as pd
def delete_sensor_data(deviceId): # noqa: E501
"""Delete sensor data
This can only be done by the logged in user. # noqa: E501
:param deviceId: Sensor Id that need to be updated
:type deviceId: int
:rtype: None
"""
try:
df = pd.read_csv("/tmp/iot.csv")
if deviceId in df['dev_id'].values :
indexNames = df[ df['dev_id'] == deviceId].index
df.drop(indexNames , inplace=True)
df.to_csv("/tmp/iot.csv")
status = 200
data = {"Success message": "Device deleted from the csv"}
else:
status = 400
data = {"Error message": "Invalid device"}
except Exception as e:
data = {"Error message": str(e)}
status = 400
return jsonify(data),status
def update_sensor_data(body): # noqa: E501
"""Updated Sensor name
# noqa: E501
:param body: Pet object that needs to be added to the store
:type body: dict | bytes
:rtype: None
"""
# noqa: E501
try:
body = connexion.request.get_json()
dev_id = body['dev_id']
device_name = body['device_name']
df = pd.read_csv("/tmp/iot.csv")
if dev_id in df['dev_id'].values :
df.loc[df['dev_id'] == dev_id, 'device_name'] = device_name
df.to_csv("/tmp/iot_updated_modifed.csv")
status = 200
data = {"Success message": "CSV updated and saved as iot_updated_modifed.csv in /tmp"}
else:
status = 400
data = {"Error message": "Invalid device"}
except Exception as e:
data = {"Error message": str(e)}
status = 400
return data, status
import connexion
import six
from flask import jsonify
from swagger_server import util
import json
import pandas as pd
def get_sensor_by_id(deviceId): # noqa: E501
try:
df = pd.read_csv("/tmp/iot.csv")
if deviceId in df['dev_id'].values :
df_deviceId = df.loc[df['dev_id'] == deviceId]
df_resp = df_deviceId[['dev_id','device_name','snr']]
# df_resp = df_resp.head(1)
data = df_resp.to_json(orient="records")
status = 200
#data = {"Success message": "Device deleted from the csv"}
else:
status = 400
data = {"Error message": "Invalid device"}
except Exception as e:
data = {"Error message": str(e)}
status = 400
return json.loads(data),status
def getmaximum(sensor): # noqa: E501
"""Find maximum sensor data by ID
Returns a list of sensor data # noqa: E501
:param sensor: Device id to search in the data
:type sensor: str
:rtype: Device
"""
return 'do some magic!'
def getminimum(sensor): # noqa: E501
"""Find minimum sensor data by ID
Returns a list of sensor data # noqa: E501
:param sensor: Device id to search in the data
:type sensor: str
:rtype: Device
"""
return 'do some magic!'
\ No newline at end of file
import connexion
import six
from flask import jsonify
from swagger_server import util
import pandas as pd
import json
def upload_post(upfile): # noqa: E501
df = pd.read_csv(upfile)
df.to_csv("/tmp/iot.csv")
data = {"message": "File Successfully uploaded"}
return data, 200
\ No newline at end of file
from connexion.apps.flask_app import FlaskJSONEncoder
import six
from swagger_server.models.base_model_ import Model
class JSONEncoder(FlaskJSONEncoder):
include_nulls = False
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
attr = o.attribute_map[attr]
dikt[attr] = value
return dikt
return FlaskJSONEncoder.default(self, o)
# coding: utf-8
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from swagger_server.models.device import Device
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment