some housekeeping

This commit is contained in:
simon 2021-07-07 19:18:06 +07:00
parent 129caa06a4
commit adde5b75c4
3 changed files with 28 additions and 18 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": false,
"python.linting.enabled": true
}

View File

@ -9,7 +9,7 @@ backup_dir="$HOME/backup"
docker exec postgres pg_dump -U aqi | gzip > "$backup_dir/pg_$time_stamp.gz" docker exec postgres pg_dump -U aqi | gzip > "$backup_dir/pg_$time_stamp.gz"
# rotate # rotate
find "$backup_dir" -type f -name "pg_*.gz" | sort -r | tail -n +15 | xargs --no-run-if-empty trash find "$backup_dir" -type f -name "pg_*.gz" | sort -r | tail -n +7 | xargs --no-run-if-empty trash
# log # log
log_file="$backup_dir/pg_status.log" log_file="$backup_dir/pg_status.log"

View File

@ -1,31 +1,36 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
script to post data to the ingest route with simulated data for testing script to post data to the ingest route with simulated data for testing
""" """
import requests
import json import json
import configparser import requests
def get_config():
""" read config file """
config_path = 'flask_aqi/config.json'
with open(config_path, 'r') as config_file:
data = config_file.read()
config = json.loads(data)
return config
# get auth # get auth
config_parser = configparser.ConfigParser()
config_parser.read('../backend/flask/config') CONFIG = get_config()
user_name = config_parser.get('aqi_monitor', "authUsername") user_name = CONFIG['aqi_monitor']['authUsername']
user_pass = config_parser.get('aqi_monitor', "authPassword") user_pass = CONFIG['aqi_monitor']['authPassword']
# example json data as from the esp8266 # example json data as from the esp8266
json_data = { example_data = '{"uptime":33,"temperature":35.36,"pressure":970.9545,"humidity":41.44336,"pm25":4.5,"pm10":6.2,"sensor_id":1}'
"uptime": 1476,
"temperature": 28.46,
"pressure": 995.0873,
"humidity": 10.52051,
"pm25": 56.5,
"pm10": 64.4
}
# make the call # make the call
response = requests.post("https://data.lpb-air.com/ingest", json=json_data, auth = (user_name, user_pass)) response = requests.post("http://localhost:5000/data/in", json=example_data, auth = (user_name, user_pass))
# print result # print result
print(response) print(response)