From: Cameron Ball Date: Sun, 2 Dec 2018 14:23:32 +0000 (+0800) Subject: Add a reminder about tomorrow's temperature X-Git-Url: http://git.cameron1729.xyz/?p=SonOfLokstallBot.git;a=commitdiff_plain;h=33689d5ba86cc1adfde1cf4914a1754d09be4568 Add a reminder about tomorrow's temperature --- diff --git a/.gitignore b/.gitignore index 4f4773f..65216c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ config.php +.ac-php-conf.json diff --git a/composer.json b/composer.json index cda6a21..da9ed2b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "require": { - "irazasyed/telegram-bot-sdk": "^2.0" + "irazasyed/telegram-bot-sdk": "^2.0", + "cmfcmf/openweathermap-php-api": "^2.4" } } diff --git a/composer.lock b/composer.lock index fdd80a0..61a4d7a 100644 --- a/composer.lock +++ b/composer.lock @@ -1,12 +1,62 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4fc59fc846328b44db644ed8cd44face", + "content-hash": "a41da94e191cd544dfcb2eaaff20f9c4", "packages": [ { + "name": "cmfcmf/openweathermap-php-api", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git", + "reference": "37f2e1178948a07c8d50d5063a15ca84b5b51f6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cmfcmf/OpenWeatherMap-PHP-Api/zipball/37f2e1178948a07c8d50d5063a15ca84b5b51f6a", + "reference": "37f2e1178948a07c8d50d5063a15ca84b5b51f6a", + "shasum": "" + }, + "require": { + "ext-xml": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8 || ^5.0.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Cmfcmf\\": "Cmfcmf" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Flach (cmfcmf)", + "email": "cmfcmf.flach@gmail.com", + "homepage": "http://cmfcmf.github.io", + "role": "Developer" + } + ], + "description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.", + "homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api", + "keywords": [ + "OpenWeatherMap", + "api", + "free", + "owm", + "weather" + ], + "time": "2018-08-30T07:35:48+00:00" + }, + { "name": "doctrine/inflector", "version": "v1.2.0", "source": { diff --git a/goodnight.php b/goodnight.php new file mode 100644 index 0000000..af9d421 --- /dev/null +++ b/goodnight.php @@ -0,0 +1,29 @@ +temperature->now->getValue(); +}, +array_filter( + iterator_to_array( + (new OpenWeatherMap(OWM_API_KEY))->getWeatherForecast(2063523, 'metric', 'en', '', 2) + ), + function($forecast) { + $forecastDayLocal = DateTimeImmutable::createFromMutable($forecast->time->from)->setTimezone(new DateTimeZone('Australia/Perth')); + return (int)(new DateTimeImmutable())->format('d') + 1 == (int)$forecastDayLocal->format('d'); + } +))); + +getTelegram()->sendMessage( + [ + 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'], + 'text' => max($temps) > 30 + ? getString('goodnightWearShorts', ceil($temps[1]) . '°', ceil(max($temps)) . '°') + : getString('goodnight', ceil($temps[1]) . '°', ceil(max($temps)) . '°'), + ] +); diff --git a/strings.php b/strings.php index 3c63795..76dee7f 100644 --- a/strings.php +++ b/strings.php @@ -4,5 +4,7 @@ return [ 'takeoutthebins' => 'Take out that BINZ #TrashSLAM 🚮', 'newbill' => '%s bill: $%s each due on the %s', 'billreminder' => '[REMINDER %d DAYS] %s bill: $%s each due on the %s', - 'drinksomewater' => '🚰 Consider drinking some water! 💦 #HydrationNation' -]; \ No newline at end of file + 'drinksomewater' => '🚰 Consider drinking some water! 💦 #HydrationNation', + 'goodnightWearShorts' => 'I\'m signing off for the night. Before I go; tomorrow it\'s going to be about %s when you get up and %s later in the day. So consider wearing summer clothes. ☀️☀️☀️', + 'goodnight' => 'I\'m signing off for the night. Before I go; tomorrow it\'s going to be about %s when you get up and %s later in the day. So consider wearing summer clothes.' +];