|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Dependency: This script requires `jq` cli installed: https://stedolan.github.io/jq/ |
| 4 | +# Install via homebrew: `brew install jq` |
| 5 | + |
| 6 | +# !!! This script is only template, you can use it to write own script to get your data from Firebase Realtime Database !!! |
| 7 | +# I'm using an Arduino ESP-32 as outside weather station and I'm storing the temperature, humidity and barometric pressure into Firebase Realtime Database. |
| 8 | +# I wrote this script to see those values directly in Raycast. This script is changing the text color based on the Light/Dark mode. |
| 9 | +# Check example folder to see the result of my script and my Firebase Realtime Database structure. |
| 10 | + |
| 11 | +# Required parameters: |
| 12 | +# @raycast.schemaVersion 1 |
| 13 | +# @raycast.title Get data from Firebase |
| 14 | +# @raycast.mode inline |
| 15 | +# @raycast.refreshTime 10m |
| 16 | +# @raycast.packageName Firebase |
| 17 | + |
| 18 | +# Optional parameters: |
| 19 | +# @raycast.icon images/firebase.png |
| 20 | +# |
| 21 | +# Documentation: |
| 22 | +# @raycast.description Get values from Firebase Realtime Database |
| 23 | +# @raycast.author Marek Mašek |
| 24 | +# @raycast.authorURL https://github.com/marekmasek |
| 25 | + |
| 26 | + |
| 27 | +# you can find API_KEY on "Project settings -> General" page in Firebase |
| 28 | +WEB_API_KEY="" |
| 29 | +# you need to create an user with email and password on "Authentication -> Users" page in Firebase |
| 30 | +EMAIL="" |
| 31 | +PASSWORD="" |
| 32 | +# This is URL to your Realtime Database in Firebase, example of DB_URL: "https://${database-name}.${database-location}.firebasedatabase.app" |
| 33 | +DB_URL="" |
| 34 | + |
| 35 | +if ! jq --version download &> /dev/null; then |
| 36 | + echo "download jq is required (https://stedolan.github.io/jq/)."; |
| 37 | + exit 1; |
| 38 | +fi |
| 39 | + |
| 40 | +# Generate access token |
| 41 | +TOKEN=$(curl -s -H "Content-Type: application/json" -d '{"email": "'$EMAIL'", "password": "'$PASSWORD'", "returnSecureToken": true}' 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key='$WEB_API_KEY | jq -r '.idToken') |
| 42 | + |
| 43 | +# Get data from Firebase Realtime Database |
| 44 | +RESPONSE=$(curl -s $DB_URL'/.json?auth='$TOKEN) |
| 45 | + |
| 46 | +# This script is changing color of the output text based on the light/dark mode activated in macOS |
| 47 | +COLOR_MODE=$(defaults read -g AppleInterfaceStyle 2>/dev/null) |
| 48 | +MAIN_COLOR="\u001b[97m" |
| 49 | + |
| 50 | +if [ ${COLOR_MODE:-"Light"} == "Light" ]; then |
| 51 | +MAIN_COLOR="\u001b[30m" |
| 52 | +fi |
| 53 | + |
| 54 | +# Get specific field values, round them and print the output |
| 55 | +echo $RESPONSE | jq -r 'def colors: |
| 56 | + { |
| 57 | + "main": "'$MAIN_COLOR'", |
| 58 | + "reset": "\u001b[0m", |
| 59 | +}; colors.reset + "Temp: " + colors.main + (.outside.temp*10.0|round/10.0|tostring) + " °C" + colors.reset +" Hum: " + colors.main + (.outside.humidity|round|tostring) + " %" + colors.reset + " BP: " + colors.main + (.outside.airPressure*10.0|round/10.0|tostring) + " hPa" + colors.reset + " Room Temp: " + colors.main + (.inside.temp*10.0|round/10.0|tostring) + " °C"' |
0 commit comments