Update Readme File #2459
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Update Readme File" | |
| on: | |
| schedule: | |
| - cron: '20 * * * *' | |
| workflow_dispatch: | |
| inputs: | |
| logLevel: | |
| description: 'Log level' | |
| required: true | |
| default: 'warning' | |
| type: choice | |
| options: | |
| - info | |
| - warning | |
| - debug | |
| tags: | |
| description: 'Test scenario tags' | |
| required: false | |
| type: boolean | |
| environment: | |
| description: 'Environment to run tests against' | |
| type: environment | |
| required: true | |
| jobs: | |
| update-readme: | |
| permissions: write-all | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Generate README | |
| run: | |
| # Reset README.md from template | |
| cp README.md.template README.md | |
| - name: Install jq | |
| run: sudo apt-get install jq | |
| # Extract reason from the API response and update README | |
| - name: Update Weather | |
| run: | | |
| # Get current date in dd/mm/yyyy format | |
| CURRENT_DATE=$(date +"%d/%m/%Y") | |
| # Replace [date] placeholder in README.md | |
| sed -i "s#\[date\]#$CURRENT_DATE#g" README.md | |
| # Get current epoch time (in seconds) | |
| NOW_EPOCH=$(date +%s) | |
| # Extract the next forecast hour (time_epoch > NOW) | |
| NEXT_FORECAST=$(jq -c --argjson now "$NOW_EPOCH" ' | |
| [ .forecast.forecastday[].hour | |
| | map(select(.time_epoch > $now)) | |
| | first ] | |
| | map(select(. != null)) | |
| | first | |
| ' tmp/forecast_response.json) | |
| echo "Next forecast" $NEXT_FORECAST | |
| TEXT=$(echo "$NEXT_FORECAST" | jq -r '.condition.text') | |
| ICON=$(echo "$NEXT_FORECAST" | jq -r '.condition.icon') | |
| COND_ID=$(echo "$NEXT_FORECAST" | jq -r '.condition.code') | |
| BNG_DAY_TEXT=$(jq -r --argjson id "$COND_ID" '.[] | select(.code == $id).day_text' tmp/condition.json) | |
| BNG_NIT_TEXT=$(jq -r --argjson id "$COND_ID" '.[] | select(.code == $id).night_text' tmp/condition.json) | |
| ISDAY=$(jq -r '.current.is_day' tmp/current_weather_response.json) | |
| AQI=$(jq -r '.current.air_quality["us-epa-index"]' tmp/forecast_response.json) | |
| PM2_5=$(jq -r '.current.air_quality.pm2_5' tmp/forecast_response.json) | |
| PM10=$(jq -r '.current.air_quality.pm10' tmp/forecast_response.json) | |
| echo $TEXT $ICON $BNG_DAY_TEXT $BNG_NIT_TEXT $ISDAY | |
| sed -i "s#\[icon\]#$ICON#g" README.md | |
| sed -i "s#\[todays_condition\]#$TEXT#g" README.md | |
| if [ "$ISDAY" -eq "1" ]; then | |
| sed -i "s#\[todays_condition_in_bengali\]#$BNG_DAY_TEXT#g" README.md | |
| else | |
| sed -i "s#\[todays_condition_in_bengali\]#$BNG_NIT_TEXT#g" README.md | |
| fi | |
| sed -i "s#\[PM2_5\]#$PM2_5#g" README.md | |
| sed -i "s#\[PM10\]#$PM10#g" README.md | |
| case "$AQI" in | |
| 1) | |
| AQI_VALUE="Good" | |
| ;; | |
| 2) | |
| AQI_VALUE="Moderate" | |
| ;; | |
| 3) | |
| AQI_VALUE="Unhealthy for sensitive group" | |
| ;; | |
| 4) | |
| AQI_VALUE="Unhealthy" | |
| ;; | |
| 5) | |
| AQI_VALUE="Very Unhealthy" | |
| ;; | |
| 6) | |
| AQI_VALUE="Hazardous" | |
| ;; | |
| *) | |
| AQI_VALUE="Unknown" | |
| ;; | |
| esac | |
| sed -i "s#\[aqi\]#$AQI_VALUE#g" README.md | |
| # Generate header once | |
| HOURLY_MD="| Time | Condition | Temp (°C) | Feels (°C) | Humidity (%) | Wind (kph) | Rain (%) |\n" | |
| HOURLY_MD+="| --- | --- | --- | --- | --- | --- | --- |\n" | |
| # Extract only upcoming hours (time_epoch >= NOW_EPOCH) | |
| HOURLY_ROWS=$(jq -r --argjson now "$NOW_EPOCH" ' | |
| .forecast.forecastday[].hour | |
| | map(select(.time_epoch >= $now)) | |
| | .[] | [ | |
| .time, | |
| (" " + .condition.text), | |
| .temp_c, | |
| .feelslike_c, | |
| .humidity, | |
| .wind_kph, | |
| .chance_of_rain | |
| ] | @tsv | |
| ' tmp/forecast_response.json|head -n 10) | |
| echo $HOURLY_MD | |
| echo $HOURLY_ROWS | |
| while IFS=$'\t' read -r t cond temp feel hum wind rain; do | |
| HOURLY_MD+="| $t | $cond | $temp | $feel | $hum | $wind | $rain |\n" | |
| done <<< "$HOURLY_ROWS" | |
| # Replace placeholder in README.md | |
| sed -i "s#\[hourly_forecast_table\]#${HOURLY_MD//$'\n'/\\n}#g" README.md | |
| LUNAR_PHASE=$(jq -r '.astronomy.astro.moon_phase' tmp/astronomy_response.json) | |
| MOONRISE=$(jq -r '.astronomy.astro.moonrise' tmp/astronomy_response.json) | |
| MOONSET=$(jq -r '.astronomy.astro.moonset' tmp/astronomy_response.json) | |
| SUNRISE=$(jq -r '.astronomy.astro.sunrise' tmp/astronomy_response.json) | |
| SUNSET=$(jq -r '.astronomy.astro.sunset' tmp/astronomy_response.json) | |
| WIND=$(jq -r '.current.wind_kph' tmp/current_weather_response.json) | |
| HUMIDITY=$(jq -r '.current.humidity' tmp/current_weather_response.json) | |
| FEELSLIKE=$(jq -r '.current.feelslike_c' tmp/current_weather_response.json) | |
| DASHBOARD="🌙 <strong>Moon Phase:</strong> $LUNAR_PHASE (Rise: $MOONRISE, Set: $MOONSET) <br>" | |
| DASHBOARD+="🌅 <strong>Sunrise:</strong> $SUNRISE | <strong>Sunset:</strong> $SUNSET <br>" | |
| DASHBOARD+="💨 <strong>Wind:</strong> $WIND kph | " | |
| DASHBOARD+="💧 <strong>Humidity:</strong> $HUMIDITY% | " | |
| DASHBOARD+="🌡️ <strong>Feels Like:</strong> $FEELSLIKE °C \n" | |
| sed -i "s#\[weather_dashboard\]#${DASHBOARD//$'\n'/\\n}#g" README.md | |
| - name: Fetch & Format Crypto Prices | |
| run: | | |
| declare -A SYMBOLS=( | |
| ["BTC"]="btcinr" | |
| ["ETH"]="ethinr" | |
| ["USDT"]="usdtinr" | |
| ["USDC"]="usdcinr" | |
| ["BNB"]="bnbinr" | |
| ) | |
| OUTPUT="" | |
| for COIN in "${!SYMBOLS[@]}"; do | |
| RESPONSE=$(curl -s "https://api.wazirx.com/api/v2/tickers/${SYMBOLS[$COIN]}") | |
| PRICE=$(echo "$RESPONSE" | jq -r '.ticker.last') | |
| HIGH=$(echo "$RESPONSE" | jq -r '.ticker.high') | |
| LOW=$(echo "$RESPONSE" | jq -r '.ticker.low') | |
| TS=$(echo "$RESPONSE" | jq -r '.at') | |
| DATE=$(date -d "@$TS" +"%Y-%m-%d %H:%M:%S IST") | |
| case $COIN in | |
| "BTC") ICON="₿";; | |
| "ETH") ICON="♦";; | |
| "USDT") ICON="💵";; | |
| "USDC") ICON="🪙";; | |
| "BNB") ICON="⚡";; | |
| *) ICON="";; | |
| esac | |
| LINE="$ICON $COIN: ₹$PRICE | 📈 H: ₹$HIGH | 📉 L: ₹$LOW " | |
| OUTPUT+="$LINE<br>" | |
| done | |
| echo -e "$OUTPUT" | |
| sed -i "s#\[crypto_prices\]#${OUTPUT//$'\n'/\\n}#g" README.md | |
| # Fetch data from your API | |
| - name: Fetch API data | |
| run: | | |
| curl -X GET https://naas.isalman.dev/no -o tmp/humour_response.json | |
| # Extract reason from the API response and update README | |
| - name: Update README with API reason | |
| run: | | |
| REASON=$(jq -r '.reason' tmp/humour_response.json) | |
| echo $REASON | |
| sed -i "s/\[funny_no_statement\]/$REASON/g" README.md | |
| - name: Get current year | |
| id: current_year | |
| run: echo "year=$(date +'%Y')" >> $GITHUB_ENV | |
| - name: Update README with current year | |
| run: | | |
| sed -i "s/\[current_year_placeholder\]/${{ env.year }}/g" README.md | |
| - name: Make script executable | |
| run: chmod +x scripts/generate_fuel_cards.sh | |
| - name: Generate fuel cards and update README | |
| run: | | |
| ./scripts/generate_fuel_cards.sh | |
| - name: Commit | |
| run: | | |
| if git diff --exit-code; then | |
| echo "No changes to commit." | |
| exit 0 | |
| else | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add . | |
| git commit -m "update" | |
| git push origin main | |
| fi |