Add a reminder about tomorrow's temperature
authorCameron Ball <cameron@cameron1729.xyz>
Sun, 2 Dec 2018 14:23:32 +0000 (22:23 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Wed, 19 Dec 2018 03:48:27 +0000 (11:48 +0800)
.gitignore
composer.json
composer.lock
goodnight.php [new file with mode: 0644]
strings.php

index 4f4773f..65216c5 100644 (file)
@@ -1 +1,2 @@
 config.php
+.ac-php-conf.json
index cda6a21..da9ed2b 100644 (file)
@@ -1,5 +1,6 @@
 {
     "require": {
-        "irazasyed/telegram-bot-sdk": "^2.0"
+        "irazasyed/telegram-bot-sdk": "^2.0",
+        "cmfcmf/openweathermap-php-api": "^2.4"
     }
 }
index fdd80a0..61a4d7a 100644 (file)
@@ -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 (file)
index 0000000..af9d421
--- /dev/null
@@ -0,0 +1,29 @@
+<?php declare(strict_types=1);
+
+require 'common.php';
+
+use Cmfcmf\OpenWeatherMap;
+
+$temps =
+       array_values(
+array_map(function($forecast) {
+    return $forecast->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)) . '°'),
+    ]
+);
index 3c63795..76dee7f 100644 (file)
@@ -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.'
+];