initial commit

This commit is contained in:
2024-06-11 21:08:44 +02:00
commit d8433ffbd8
391 changed files with 37223 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
# airly
Show air quality in your area
![CAQI](airly.png)
# Dependencies
Python 3
**Packages names in Debian based distros**:
python3
**Packages names in Arch Linux**:
python
# Usage
There are two ways to set up airly blocklet. You able to specify options in
**"Settings"** section inside [airly](airly) file. And if you not allowed to
edit airly file, or if you want to use multiple instances of airly block, you
could make .yml config file for each instance in **~/.config/i3blocks-airly/**
directory.
Now keep in mind, that there are also two ways to specify measurements places.
One way is to specify the installationId which may be obtained from the API or
whe airly.eu widgets.
Another way is to use the place lattitude and longitude and specify them explicitly
in the config file, which would give interpolated measurements.
An apikey is a must and may be obtained by registering an user account on airly.eu
Now add a section to your i3blocks.conf like following:
```INI
[airly]
command=$SCRIPT_DIR/airly #note that this line is optional
interval=600
min_width=CAQI: 99
```
If you want to use instance mechanism of i3blocks, you should make config file
in directory **~/.config/i3blocks-airly/** with following structure:
```YML
apikey: 'xxxx' #get it from airly.eu
# then
installationId: 2222
# or
lat: 10.0000
lng: 10.0000
```
The `apikey` key is mandatory and either `installationId` or `lat&lng` have to be chosen.
The minimal config file is:
```YML
apikey: xxxxxxxxxxxxxxxxx
installationId: 2222
```
When config files is created, add an instance option with name of config file
to your i3blocks.conf. Let's imagine, that we have the
~/.config/i3blocks-airly/home.yml file, then airly section should be:
```ini
[airly]
instance=home
interval=600
min_width=CAQI: 99
```
After configuring blocklet restart your window manager.
New block should appear in the i3bar.

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B

103
.config/i3blocks/airly/airly.py Executable file
View File

@@ -0,0 +1,103 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright © 2019 Kudlaty 01 <kudlok@mail.ru>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import getopt, requests, urllib, yaml, sys, os
gconfig = {
'apikey': 'example_api_key',
'installationId': 2955,
# uncomment if lat/long is preferred instead of sensorId
# 'lat': '',
# 'lng': ''
}
class AirlyApiClient:
def __init__(self, config=None):
"""init with optionally config"""
self.config = config or self.parseConfig(self.parseInstance())
self.apiUrl = 'https://airapi.airly.eu/v2/measurements/%s?' % ('installation' if 'installationId' in self.config else 'point')
def parseInstance(self):
""" parse the instance environment variable """
instance = ''
try:
instance = os.environ['BLOCK_INSTANCE']
except KeyError:
return None
finally:
if len(instance):
return instance
return None
def parseConfig(self, instance):
"""parse the instance-specific config file or a default one"""
_instance = instance or self.parseInstance()
xdgHome = os.environ['XDG_CONFIG_HOME'] or os.environ['HOME'] + '/.config'
configPath = xdgHome + '/i3blocks-airly/%s.yml' % (_instance or 'config')
try:
with open(configPath, 'r') as stream:
config=yaml.load(stream)
return config
except:
global gconfig
return gconfig
def getMeasurement(self, config=None):
"""get the measurements for the place"""
cfg = config or self.config
r = requests.get(self.apiUrl + urllib.parse.urlencode(self.config))
self.lastResult = r.json()
return self.lastResult
def getCurrentMeasurement(self, measurement=None):
"""get only the current measurement"""
m = measurement or self.getMeasurement()
return m['current']['indexes']
def getCaqiMeasurement(self, measurement=None):
"""get only the current CAQUI measurement"""
m = measurement or self.getCurrentMeasurement()
caqi=next(c for c in m if c['name'] == 'AIRLY_CAQI')
return caqi
def getAirQualityIndex(self, caqiMeasurement=None):
"""get the air quality index value from given CAQI measurement
it's current measuement by default"""
m = caqiMeasurement or self.getCaqiMeasurement()
index = m['value']
return index
def getColor(self, measurement=None):
"""get color for given air quality indes"""
m = measurement or self.getCaqiMeasurement()
return m['color']
def displayResult(self,jsonData=None):
"""display the measurement result"""
result = self.getAirQualityIndex()
print(round(result,2))
print(round(result))
print(self.getColor())
def main(argv):
args=argv
client = AirlyApiClient()
client.displayResult()
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -0,0 +1,4 @@
apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# installationId: 204
lat: 40.062006
lng: 29.940984