I've spent a few days looking at this on and off but I can't work out what I'm doing wrong. I've tried to follow this:
Passing Variables between functions
I'm still not clear on what I need to do though.
This is what I have presently but I've tried various permutations:
def root():
hivelogin()
occupancy()
print (hiveSessionId)
return ("Done")
I need this to work in lots of places but I'll use hivelogin() as the example:
def hivelogin():
import requests
url = "https://api.prod.bgchprod.info:443/omnia/auth/sessions"
payload = "{\n \"sessions\": [{\n \"username\": \"xxxxxxxxxxx\",\n \"password\": \"xxxxxxxxxxx\",\n \"caller\": \"WEB\"\n }]\n}"
headers = {
'Content-Type': "application/vnd.alertme.zoo-6.1+json",
'Accept': "application/vnd.alertme.zoo-6.1+json",
'X-Omnia-Client': "Hive Web Dashboard",
'Cache-Control': "no-cache",
}
response = requests.request("POST", url, data=payload, headers=headers)
data=response.json()
hiveSessionId = (data['sessions'][0]['sessionId'])
session['hiveSessionId'] = (data['sessions'][0]['sessionId'])
return hiveSessionId
I've got round it by using a session variable in this case but I don't want to have to do this when I've probably got loads of variables I need to pass around.
So, what I need is for hiveSessionId to my root (or any other) function.
If I do:
def root(hiveSessionId=None)
I get nothing - as I'd expect.
If I do:
def root(hiveSessionId=hiveSessionId)
I get an error - as I'd expect.
So, the simple question is how I pass a variable from the function that creates it to any other function in my app - probably between routes as I'm using Flask but I'm using MySQL to give some persistence.
I've done a tiny bit of coding in the past with PHP but please bear in mind that I'm old, been learning Python for about 3 weeks, and this is my first app. I did the "Hello world" thing, watched a video about Python on Youtube and then did this so it's probably going to make you want to cry.
EDIT: Simplified pseudo version of what I want:
def a():
b()
return x
def b():
x=10