This commit is contained in:
parent
85b306e6ad
commit
fcbd0e9426
@ -137,3 +137,4 @@ dmypy.json
|
|||||||
*.yml
|
*.yml
|
||||||
contrib/*
|
contrib/*
|
||||||
postman/*
|
postman/*
|
||||||
|
*.wav
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -131,3 +131,4 @@ dmypy.json
|
|||||||
#Pycharm
|
#Pycharm
|
||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
*wav
|
@ -10,3 +10,4 @@ xeger
|
|||||||
pika
|
pika
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
marshmallow
|
marshmallow
|
||||||
|
flask-serialize
|
@ -22,7 +22,7 @@ RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
|||||||
RELEASEMODE = os.environ.get("INPUT_SERVICE_RELEASEMODE", "dev")
|
RELEASEMODE = os.environ.get("INPUT_SERVICE_RELEASEMODE", "dev")
|
||||||
|
|
||||||
RABBITMQ_HOST = os.getenv("INPUT_RABBITMQ_HOSTNAME", "localhost")
|
RABBITMQ_HOST = os.getenv("INPUT_RABBITMQ_HOSTNAME", "localhost")
|
||||||
RABBITMQ_EXCHANGE = os.getenv("INPUT_RABBITMQ_EXCHANGE", "")
|
RABBITMQ_EXCHANGE = os.getenv("INPUT_RABBITMQ_EXCHANGE", "dev")
|
||||||
RABBITMQ_QUEUE = os.getenv("INPUT_RABBITMQ_QUEUE", "wave-extract")
|
RABBITMQ_QUEUE = os.getenv("INPUT_RABBITMQ_QUEUE", "wave-extract")
|
||||||
RABBITMQ_USERNAME = os.getenv("INPUT_RABBITMQ_USERNAME", "rabbitmq")
|
RABBITMQ_USERNAME = os.getenv("INPUT_RABBITMQ_USERNAME", "rabbitmq")
|
||||||
RABBITMQ_PASSWORD = os.getenv("INPUT_RABBITMQ_PASSWORD", "rabbitmq")
|
RABBITMQ_PASSWORD = os.getenv("INPUT_RABBITMQ_PASSWORD", "rabbitmq")
|
||||||
|
@ -3,7 +3,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
from xeger import Xeger
|
from xeger import Xeger
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
from flask import request, jsonify
|
from flask import request
|
||||||
import requests
|
import requests
|
||||||
from db import db
|
from db import db
|
||||||
from models import SampleMetadata
|
from models import SampleMetadata
|
||||||
@ -28,6 +28,8 @@ class SampleResource(Resource):
|
|||||||
Sample endpoint
|
Sample endpoint
|
||||||
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
|
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
|
||||||
"""
|
"""
|
||||||
|
samplemetadatas_schema = SampleMetadata(many=True,
|
||||||
|
exclude=['id', 'device_id', 'device_date', 'tag', 'timestamp'])
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
@ -58,7 +60,7 @@ class SampleResource(Resource):
|
|||||||
validate_errors = SampleSchema().validate(desc)
|
validate_errors = SampleSchema().validate(desc)
|
||||||
if validate_errors:
|
if validate_errors:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"Input JSON did not conform to schema. It was: {}", desc)
|
"Input JSON did not conform to schema. It was: {}".format(desc))
|
||||||
return {'err_msg': 'Input JSON schema invalid'}, 417
|
return {'err_msg': 'Input JSON schema invalid'}, 417
|
||||||
|
|
||||||
xeger = Xeger(limit=30)
|
xeger = Xeger(limit=30)
|
||||||
@ -105,6 +107,8 @@ class SampleParameterResource(Resource):
|
|||||||
Sample endpoint with parameters
|
Sample endpoint with parameters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
samplemetadata_schema = SampleMetadata(many=False)
|
||||||
|
|
||||||
def get(self, tag: str):
|
def get(self, tag: str):
|
||||||
"""
|
"""
|
||||||
Get a specific item
|
Get a specific item
|
||||||
@ -112,4 +116,4 @@ class SampleParameterResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
||||||
return sample, 200
|
return self.samplemetadata_schema.dump(sample), 200
|
||||||
|
@ -14,8 +14,7 @@ __version__text__ = "1"
|
|||||||
|
|
||||||
|
|
||||||
class SampleSchema(Schema):
|
class SampleSchema(Schema):
|
||||||
""" /v1/email/pay - POST
|
"""
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- date (date)
|
- date (date)
|
||||||
- device_id (str)
|
- device_id (str)
|
||||||
|
23
tester.py
Normal file
23
tester.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import requests
|
||||||
|
import os.path
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
#URL = "https://birb.kmlabz.com/api/input/v1/sample"
|
||||||
|
#URL = "http://spitfire:30069/api/input/v1/sample"
|
||||||
|
URL = "http://localhost:5000/sample"
|
||||||
|
|
||||||
|
FILE = 'CommonStarling_100962.wav'
|
||||||
|
|
||||||
|
files = {
|
||||||
|
"file": (os.path.basename(FILE), open(FILE,'rb').read(), 'audio/wave', {'Content-length' : os.path.getsize(FILE)}),
|
||||||
|
"description" : (None, json.dumps({'date' : datetime.now().isoformat(), 'device_id' : '123'}), "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
|
r = requests.post(URL,files=files)
|
||||||
|
print("Content: ", r.content)
|
||||||
|
print("Headers:", r.headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
|
#print(r.json())
|
Loading…
Reference in New Issue
Block a user