Hi!
I want to upload some data from my local weewx-system (running on a raspberry pi) to farmOS and wrote the following python-script to parse the data and load it up by curl:
import requests
from bs4 import BeautifulSoup
import json
import subprocess
url = “http://192.168.188.23/weewx”
header = {“User-Agent”: ‘Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/116.0 Firefox/116.0’}
seite = requests.get(url, headers=header)
soup = BeautifulSoup(seite.content, ‘html.parser’)
temperatur = soup.find(“td”, text=“Aussentemperatur”).find_next_sibling(“td”).text
Remove the " C" from the temperature string
temperatur = temperatur.replace(" C", “”)
Timestamp generieren
import datetime
timestamp = datetime.datetime.now().isoformat()
Daten als JSON-String vorbereiten
data = {
"timestamp": timestamp, "Temperatur": float(temperatur)
}
json_data = json.dumps(data)
JSON-Daten an die Ziel-URL mit curl senden
curl_command = ‘curl -H “Content-Type: application/json” -X POST -d '’ + json_data + ‘' https://lindhagen.farmos.net/api/data_stream/[privae_key]/data’
subprocess.run(curl_command, shell=True, check=True)
When i run this script on the weewx-machine i get the html-code for the following result:
So, what can I do to solve this login-problem??