I am hoping someone can help me find a way to pass the variables I post when calling my POST service (script1) into script2 when it gets imported.
I have this script1 below as a POST rest service built using flask
from testingdf import *
from flask import Flask, json, request
app = Flask(__name__)
@app.route("/results", methods=['POST'])
def createResults():
entry = request.get_json().get('entry', '')
passcode = request.get_json().get('passcode', '')
print "**testing results**"
print results
response = app.response_class(
response=json.dumps(results),
status=200,
mimetype='application/json'
)
return json.dumps(results)
I want to use script1 to call script 2 below and return script 2 output (results) as a json response from script 1 api:
import pandas as pd
df = pd.DataFrame()
number = [21, 44, 31, 553, 63, 35]
access = ["denied", "Try Again", "Retry", "Accepted", "Error", "Success"]
def mapping(entry, passcode):
team = ''
if entry in range(20,30):
team = 'Revolt'
elif (entry in range(40,50)) and (passcode == 'Try Again'):
team = 'Strike'
elif (entry in range(60,100)) and (passcode == 'Error'):
team = 'Exception'
return team
testInput = zip(entry, passcode)
for number, access in testInput:
Team = mapping(number, access)
df = df.append({'Access Message': access, 'Number': number}, ignore_index=True)
results = {
'Entry' : number,
'Outcome' : access,
'team': team
}
I used from testingdf import *
to import script2
into script1
however whenever I call my api it runs script2
first and the variables
that I pass in the request body return as unrecognized, which is an expected behavior since the imported module is executed first. Is there another way around this?
How can I import script2
and it's variables without having it executed initially when I call my api?