Skip to content

Instantly share code, notes, and snippets.

@stevenleeg
Created November 30, 2021 00:38
Show Gist options
  • Save stevenleeg/ccca021fa2c811427f7dd109937e3195 to your computer and use it in GitHub Desktop.
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
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