weather ags
This commit is contained in:
+16
-5
@@ -1,3 +1,5 @@
|
||||
import Weather from "./weather_service.js"
|
||||
|
||||
export default () => Widget.Box(
|
||||
{
|
||||
class_name: "weather",
|
||||
@@ -146,18 +148,27 @@ export default () => Widget.Box(
|
||||
},
|
||||
Widget.Label({
|
||||
class_name: "title",
|
||||
css: "color: black;font-size: 20px;",
|
||||
css: "color: black;font-size: 25px;",
|
||||
wrap: true,
|
||||
label: "",
|
||||
hpack: "start"
|
||||
// label: "",
|
||||
hpack: "start",
|
||||
setup: self => self.hook(Weather, () => {
|
||||
Weather.weatherData
|
||||
self.label = `${Weather._temperatureWeather.current_condition[0].weatherCode}`
|
||||
})
|
||||
}),
|
||||
Widget.Box({hexpand: true}),
|
||||
Widget.Label({
|
||||
class_name: "title",
|
||||
css: "color: black;margin-right: 10px;font-size: 20px;",
|
||||
wrap: true,
|
||||
label: "↑ 10 ↓ 4 FRI",
|
||||
hpack: "end"
|
||||
// label: "↑ 10 ↓ 4 FRI",
|
||||
hpack: "end",
|
||||
setup: self => self.hook(Weather, () => {
|
||||
// self.label = "hello world"
|
||||
print(Weather.weatherData)
|
||||
self.label = `↑ ${Weather._temperatureWeather.weather[0].maxtempC} ↓ ${Weather._temperatureWeather.weather[0].mintempC} ${Weather._temperatureWeather.weather[0].date}`
|
||||
}),
|
||||
})
|
||||
),
|
||||
Widget.Box(
|
||||
|
||||
+1365
-259
File diff suppressed because it is too large
Load Diff
@@ -11,21 +11,22 @@ class Weather extends Service {
|
||||
}
|
||||
|
||||
get weatherData() {
|
||||
Utils.execAsync(['bash', '-c', "openweathermap ags"]).catch(print);
|
||||
this._temperatureWeather = JSON.parse(Utils.exec(['python', "wttr.py"])) // .then(temp => {console.log(temp)}).catch(print);
|
||||
return this._temperatureWeather
|
||||
}
|
||||
|
||||
get temperatureWeather() {
|
||||
return this._temperatureWeather;
|
||||
}
|
||||
setTemperatureWeather(temp) {
|
||||
this._temperatureWeather = temp;
|
||||
this.emit('changed');
|
||||
}
|
||||
// get temperatureWeather() {
|
||||
// return this._temperatureWeather;
|
||||
// }
|
||||
// setTemperatureWeather(temp) {
|
||||
// this._temperatureWeather = temp;
|
||||
// this.emit('changed');
|
||||
// }
|
||||
|
||||
get tooltip() {
|
||||
return this._tooltip;
|
||||
}
|
||||
setTooltip(text) { this._tooltip = text }
|
||||
// get tooltip() {
|
||||
// return this._tooltip;
|
||||
// }
|
||||
// setTooltip(text) { this._tooltip = text }
|
||||
}
|
||||
|
||||
export default new Weather();
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/python
|
||||
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
WEATHER_CODES = {
|
||||
'113': '☀️',
|
||||
'116': '⛅️',
|
||||
'119': '☁️',
|
||||
'122': '☁️',
|
||||
'143': '🌫',
|
||||
'176': '🌦',
|
||||
'179': '🌧',
|
||||
'182': '🌧',
|
||||
'185': '🌧',
|
||||
'200': '⛈',
|
||||
'227': '🌨',
|
||||
'230': '❄️',
|
||||
'248': '🌫',
|
||||
'260': '🌫',
|
||||
'263': '🌦',
|
||||
'266': '🌦',
|
||||
'281': '🌧',
|
||||
'284': '🌧',
|
||||
'293': '🌦',
|
||||
'296': '🌦',
|
||||
'299': '🌧',
|
||||
'302': '🌧',
|
||||
'305': '🌧',
|
||||
'308': '🌧',
|
||||
'311': '🌧',
|
||||
'314': '🌧',
|
||||
'317': '🌧',
|
||||
'320': '🌨',
|
||||
'323': '🌨',
|
||||
'326': '🌨',
|
||||
'329': '❄️',
|
||||
'332': '❄️',
|
||||
'335': '❄️',
|
||||
'338': '❄️',
|
||||
'350': '🌧',
|
||||
'353': '🌦',
|
||||
'356': '🌧',
|
||||
'359': '🌧',
|
||||
'362': '🌧',
|
||||
'365': '🌧',
|
||||
'368': '🌨',
|
||||
'371': '❄️',
|
||||
'374': '🌧',
|
||||
'377': '🌧',
|
||||
'386': '⛈',
|
||||
'389': '🌩',
|
||||
'392': '⛈',
|
||||
'395': '❄️'
|
||||
}
|
||||
|
||||
weather: json = requests.get("https://wttr.in/tomsk?format=j1").json()
|
||||
|
||||
# data = json.load(weather)
|
||||
|
||||
weather['current_condition'][0]['weatherCode'] = WEATHER_CODES[weather['current_condition'][0]['weatherCode']]
|
||||
|
||||
print(json.dumps(weather))
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
weather=$(curl wttr.in/tomsk\?format\=j1)
|
||||
|
||||
echo weather
|
||||
Reference in New Issue
Block a user