gistfile1.txt
· 2.8 KiB · Text
Raw
#!/bin/bash
set -e
# https://dev.netatmo.com/apidocumentation/weather#Available-data og velg værstasjon
# Filter på denne url i inspectoren for å få module ID og device ID
# https://app.netatmo.net/api/simplifiedfuturemeasure
# ELLER
# Gå til https://weathermap.netatmo.com/ og finn et punkt, hent URL fra "share"
# https://weathermap.netatmo.com//?zoom=16.1802283695561&type=temp¶m=Filter&stationid=70%3Aee%3A50%3A2c%3A91%3A60&maplayer=Map&lang=undefined
# stationid=70%3Aee%3A50%3A2c%3A91%3A60 blir da device_id, renskrevet til 70:ee:50:2c:91:60 (replace %3A med :)
device_id="70:ee:50:2c:91:60"
module_id="02:00:00:2c:b2:30"
random_agent=$(shuf -n 1 <(curl -fsSL https://gist.githubusercontent.com/jakebathman/e57bad07fae95f4776f2588c919777d7/raw/cb998ab2c5e08501722544923c3f6b41e373d88b/user-agents.txt | grep -v '^$'))
access_token=$(curl --silent -A "$random_agent" https://weathermap.netatmo.com | grep 'accessToken' | sed -E 's/.*accessToken: "(.*)",/\1/')
# Time and 6 hours ago in Unix time
date_end=$(date +%s)
date_begin=$(($date_end - 3600))
# 6 hours in unix time is 21600
# 3 hours in unix time is 10800
# 1 hour in unix time is 3600
temp_humidity=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \
-H "User-Agent: $random_agent" \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H "Authorization: Bearer $access_token" \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Origin: https://weathermap.netatmo.com' \
-H 'DNT: 1' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Sec-GPC: 1' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
--data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"'"$device_id"'","module_id":"'"$module_id"'","type":"Temperature,Humidity"}' | jq '.body | last | .value[0][0]')
pressure=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \
-H "User-Agent: $random_agent" \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br, zstd' \
-H "Authorization: Bearer $access_token" \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Origin: https://weathermap.netatmo.com' \
-H 'DNT: 1' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Sec-GPC: 1' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
--data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"70:ee:50:2c:91:60","module_id":"70:ee:50:2c:91:60","type":"Pressure"}' | jq '.body | last | .value[0][0]')
# echo "Tid:"
echo "Temperatur: $temp_humidity"
echo "Pressure: $pressure"
| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | # https://dev.netatmo.com/apidocumentation/weather#Available-data og velg værstasjon |
| 5 | # Filter på denne url i inspectoren for å få module ID og device ID |
| 6 | # https://app.netatmo.net/api/simplifiedfuturemeasure |
| 7 | |
| 8 | # ELLER |
| 9 | # Gå til https://weathermap.netatmo.com/ og finn et punkt, hent URL fra "share" |
| 10 | # https://weathermap.netatmo.com//?zoom=16.1802283695561&type=temp¶m=Filter&stationid=70%3Aee%3A50%3A2c%3A91%3A60&maplayer=Map&lang=undefined |
| 11 | # stationid=70%3Aee%3A50%3A2c%3A91%3A60 blir da device_id, renskrevet til 70:ee:50:2c:91:60 (replace %3A med :) |
| 12 | |
| 13 | device_id="70:ee:50:2c:91:60" |
| 14 | module_id="02:00:00:2c:b2:30" |
| 15 | |
| 16 | random_agent=$(shuf -n 1 <(curl -fsSL https://gist.githubusercontent.com/jakebathman/e57bad07fae95f4776f2588c919777d7/raw/cb998ab2c5e08501722544923c3f6b41e373d88b/user-agents.txt | grep -v '^$')) |
| 17 | access_token=$(curl --silent -A "$random_agent" https://weathermap.netatmo.com | grep 'accessToken' | sed -E 's/.*accessToken: "(.*)",/\1/') |
| 18 | |
| 19 | # Time and 6 hours ago in Unix time |
| 20 | date_end=$(date +%s) |
| 21 | date_begin=$(($date_end - 3600)) |
| 22 | # 6 hours in unix time is 21600 |
| 23 | # 3 hours in unix time is 10800 |
| 24 | # 1 hour in unix time is 3600 |
| 25 | |
| 26 | |
| 27 | temp_humidity=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \ |
| 28 | -H "User-Agent: $random_agent" \ |
| 29 | -H 'Accept: application/json, text/plain, */*' \ |
| 30 | -H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \ |
| 31 | -H 'Accept-Encoding: gzip, deflate, br, zstd' \ |
| 32 | -H "Authorization: Bearer $access_token" \ |
| 33 | -H 'Content-Type: application/json;charset=utf-8' \ |
| 34 | -H 'Origin: https://weathermap.netatmo.com' \ |
| 35 | -H 'DNT: 1' \ |
| 36 | -H 'Connection: keep-alive' \ |
| 37 | -H 'Sec-Fetch-Dest: empty' \ |
| 38 | -H 'Sec-Fetch-Mode: cors' \ |
| 39 | -H 'Sec-Fetch-Site: cross-site' \ |
| 40 | -H 'Sec-GPC: 1' \ |
| 41 | -H 'Pragma: no-cache' \ |
| 42 | -H 'Cache-Control: no-cache' \ |
| 43 | --data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"'"$device_id"'","module_id":"'"$module_id"'","type":"Temperature,Humidity"}' | jq '.body | last | .value[0][0]') |
| 44 | |
| 45 | pressure=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \ |
| 46 | -H "User-Agent: $random_agent" \ |
| 47 | -H 'Accept: application/json, text/plain, */*' \ |
| 48 | -H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \ |
| 49 | -H 'Accept-Encoding: gzip, deflate, br, zstd' \ |
| 50 | -H "Authorization: Bearer $access_token" \ |
| 51 | -H 'Content-Type: application/json;charset=utf-8' \ |
| 52 | -H 'Origin: https://weathermap.netatmo.com' \ |
| 53 | -H 'DNT: 1' \ |
| 54 | -H 'Connection: keep-alive' \ |
| 55 | -H 'Sec-Fetch-Dest: empty' \ |
| 56 | -H 'Sec-Fetch-Mode: cors' \ |
| 57 | -H 'Sec-Fetch-Site: cross-site' \ |
| 58 | -H 'Sec-GPC: 1' \ |
| 59 | -H 'Pragma: no-cache' \ |
| 60 | -H 'Cache-Control: no-cache' \ |
| 61 | --data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"70:ee:50:2c:91:60","module_id":"70:ee:50:2c:91:60","type":"Pressure"}' | jq '.body | last | .value[0][0]') |
| 62 | |
| 63 | # echo "Tid:" |
| 64 | echo "Temperatur: $temp_humidity" |
| 65 | echo "Pressure: $pressure" |
| 66 |