Last active
March 17, 2022 19:08
-
-
Save roger-king/b25d7bf00cf4f6bb3c891481ec105386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import os | |
# This is a library used to connect to a database (mysql, postgres, sqlite, etc) | |
from sqlalchemy import create_engine | |
def fetch_device(): | |
# This should make a GET request to the URL with the path of /api/device | |
# requests library is something that needs to be installed. Usua | |
device = requests.get(f"http://localhost:3000/api/device") | |
# This is a mocked value of the above return | |
return {"deviceName": "testing_device_1", "deviceStatus": "ready"} | |
def main(): | |
try: | |
engine = create_engine("mysql://user:password@server") | |
except: | |
print("Cannot connect to MYSQL DB: ") | |
os.exit(1) | |
device_info = fetch_device() | |
# Typically will be a list of record returned | |
rules = engine.exeute( | |
f"select action from rules where deviceName = {device_info.deviceName} and deviceStatus = {device_info.deviceStatus}" | |
) | |
if len(rules) == 0: | |
print("unkown") | |
return | |
print("ambigious") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment