PakAirQuality / Roadmap

Links and resources for global and local air quality
0 stars 0 forks source link

Automated hourly air quality updates on social media #2

Open abid-omar opened 1 year ago

abid-omar commented 1 year ago
  1. Schedule to run every hour.
  2. GET AirVisual API https://api.airvisual.com/v2/city?city=Lahore&state=Punjab&country=Pakistan&key=HIDDEN
  3. FORMAT Date/Time as DD-MM-YYYY HH:mm to Pakistan Timezone
  4. Run Javascript Code to create AQI
  5. Create social media post: 13-09-2023 21:00; PM2.5 conc. 73 μg/m³; 160 Air Quality Index (AQI); #Unhealthy
var AQI;
var P2INDEX;
if (inputData.AQIUS > 800) {
  AQI='Beyond Index #Airpocalypse🤯🤯🤯🤯🤯'
  } else if (inputData.AQIUS > 500) {
  AQI='Beyond Index'
} else if (inputData.AQIUS > 300) {
  AQI='#Hazardous 😱'
} else if (inputData.AQIUS > 200) {
  AQI='Very #Unhealthy 😰'
} else if (inputData.AQIUS > 150) {
  AQI='#Unhealthy'
} else if (inputData.AQIUS > 100) {
  AQI='Unhealthy for #Sensitive Groups'
} else if (inputData.AQIUS > 50) {
  AQI='#Moderate'
} else if (inputData.AQIUS <= 50) {
  AQI='#Good ❤'
} 

if (inputData.P2CONC > 800) {
  P2INDEX='Beyond Index #Airpocalypse 🤯🤯🤯🤯🤯'
} else if (inputData.P2CONC >= 500) {
  P2INDEX='Beyond Index'
} else if (inputData.P2CONC >= 250.5) {
  P2INDEX='#Hazardous 😱'
} else if (inputData.P2CONC >= 150.5) {
  P2INDEX='Very #Unhealthy 😰'
} else if (inputData.P2CONC >= 55.5) {
  P2INDEX='#Unhealthy' 
} else if (inputData.P2CONC >= 35.5) {
  P2INDEX='Unhealthy for #Sensitive Groups'
} else if (inputData.P2CONC > 12) {
  P2INDEX='#Moderate'
} else if (inputData.P2CONC <= 12) {
  P2INDEX='#Good ❤'
} 

return {AQI};
return {P2INDEX};
abid-omar commented 1 year ago

We have been using Zapier to create the hourly tweets since 2016. Since the Twitter integration is no longer available, we are looking for alternative open source solutions.

One possible solution is https://github.com/automatisch/automatisch

See https://zapier.com/l/twitter-integration-faq

AirVisual GET Lahore - v1