Frames

FirstFrame

0
1<?php
2declare(strict_types=1);
3
4require __DIR__ . '/vendor/autoload.php';
5
6use Twilio\Rest\Client;
7
8require_once('./config.php');
9
10$dark_sky_key = getenv('DARKSKY_SECRET');
11$dark_sky_uri = sprintf('https://api.darksky.net/forecast/%s/36.162663,-86.781601,%s',
12 $dark_sky_key,
13 time() + 43200
14);
15
16$weather_data = json_decode(file_get_contents($dark_sky_uri), true);
17
18$sid = getenv('SID');
19$token = getenv('TOKEN');
20$to_number = getenv('TO_NUMBER');
21$from_number = getenv('FROM_NUMBER');
22$to_name = getenv('TO_NAME');
23$client = new Client($sid, $token);
24$chance = $weather_data['currently']['precipProbability'];
25$precipType = $weather_data['currently']['precipType'];
26
27$body = sprintf('Hey %s, it\'s going to %s tomorrow (chance: %s)! Text your friends!',
28 $to_name,
29 $precipType,
30 $chance
31);
32$client->messages->create(
33 $to_number,
34 [
35 'from' => $from_number,
36 'body' => $body
37 ]
38);
39
Watch expressions