Package: airQ
airQ v0.3.3A near real time Air Quality Indication Data Collection Service( for India ), made with :heart:Consider putting :star: to show love & supportCompanion repo located at :airQ-insight, to power visualizationwhat does it do ?Air quality data collector, collected from180+ground monitoring stations( spread across India )UnreliableJSONdataset is fetched fromhere, which gives current hour's pollutant statistics, from all monitoring station(s), spread acrossIndia, which are then objectified, cleaned, processed & restructured into proper format and pushed into*.jsonfileAir quality data, given byminimum,maximum&averagepresence of pollutants such asPM2.5,PM10,CO,NH3,SO2,OZONE&NO2, along withtimeStamp, grouped under stations( from where these were collected )Automated data collection done using systemd( hourly )installationairQcan easily be installed from PyPI using pip.$pipinstallairQ--user# or may be use pip3$python3-mpipinstallairQ--user# if previous one doesn't workusageAfter installingairQ, run it using following command$cd# currently at $HOME$airQ# improper invokationairQ-AirQualityDataCollector$airQ`sink-file-path_(*.json)_`FormakingmodificationsonairQ-collecteddata(collectedpriortothisrun),passthatJSONpath,whileinvokingairQ;)BadInput
$airQ./data/data.json# proper invokationautomationWell my plan was to automate this data collection service, so that it'll keep running in hourly fashion, and keep refreshing datasetAnd for that, I've usedsystemd, which will use asystemd.timerto trigger execution ofairQevery hour i.e. after a delay of1h, counted from last execution ofairQ, periodicallyFor that we'll require to add two files,*.service&*.timer( placed in./systemd/)airQ.serviceWell our service isn't supposed to run always, only when timer trigger asks it to run, it'll run. So in[Unit]section, it's declared itWants,airQ.timer[Unit]
Description=Air Quality Data collection service
Wants=airQ.timerYou need to set absolute path of current working directory inWorkingDirectoryfield of[Service]unit declarationExecStartis the command, to be executed when this service unit is invoked byairQ.timer, so absolute installation path ofairQand absolute sink path( *.json )is requiredMake sure you updateUserfield, to reflect changes properly, as per your system.If you just add aRestartfield under[Service]unit & give it a valuealways, we can make this script running always, which is helpful for running Servers, but we'll trigger execution of script usingsystemd.timer, pretty much likecron, but much more used & supported in almost all linux based distros[Service]
User=anjan
WorkingDirectory=/absolute-path-to-current-working-directory/
ExecStart=/absolute-path-to-airQ /home/user/data/data.jsonThis declaration, makes this service a required dependency formulti-user.target[Install]
WantedBy=multi-user.targetairQ.timerPretty much same asairQ.service, onlyRequires,airQ.serviceas one strong dependency, because that's the service which is to be run when this timer expires[Unit]
Description=Air Quality Data collection service
Requires=airQ.serviceUnitfield specifies which service file to execute when timer expires.
You can simply skip this field, if you have created a./systemd/*.servicefile of same name as./systemd/*.timerAs we're interested in running this service every1h( relative to last execution of airQ.service ), we've specifiedOnUnitActiveSecfield to be1h[Timer]
Unit=airQ.service
OnUnitActiveSec=1hMakes it an dependency oftimers.target, so that this timer can be installed[Install]
WantedBy=timers.targetautomation in ACTIONNeed to place files present./systemd/*into/etc/systemd/system/, so thatsystemdcan find these service & timer easily.$sudocp./systemd/*/etc/systemd/system/We need to reloadsystemddaemon, to let it explore newly added service & timer unit(s).$sudosystemctldaemon-reloadLets enable our timer, which will ensure our timer will keep running even after system reboot$sudosystemctlenableairQ.timerTime to start this timer$sudosystemctlstartairQ.timerSo an immediate execution of our script to be done, and after completion of so, it'll again be executed1hlater, so that we get refreshed dataset.Check status of this timer$sudosystemctlstatusairQ.timerCheck status of this service$sudosystemctlstatusairQ.serviceConsider running your instance ofairQon Cloud, mine running onAWS LightSailvisualizationThis service is supposed to only collect data & properly structure it, but visualization part is done atairQ-insightHoping it helps:wink: