Created
November 30, 2021 00:38
-
-
Save stevenleeg/ccca021fa2c811427f7dd109937e3195 to your computer and use it in GitHub Desktop.
A simple script for scraping measurements from an AirVisual meter and posting them to a URL
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 tempfile | |
import json | |
import requests | |
from smb.SMBConnection import SMBConnection | |
username = '' | |
password = '' | |
host = '0.0.0.0' | |
conn = SMBConnection(username, password, 'test', host, is_direct_tcp=True) | |
conn.connect(host, 445) | |
shares = conn.listShares() | |
file_obj = tempfile.NamedTemporaryFile() | |
file_attr, filesize = conn.retrieveFile('airvisual', 'latest_config_measurements.json', file_obj) | |
conn.close() | |
file_obj.seek(0) | |
latest_reading = json.loads(file_obj.read()) | |
print(json.dumps(latest_reading)) | |
requests.post('[some url here]', json=latest_reading) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment