-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvsnotifier.php
58 lines (53 loc) · 1.72 KB
/
pvsnotifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/php
<?php
require('twitteroauth/autoload.php');
use Abraham\TwitterOAuth\TwitterOAuth;
date_default_timezone_set('GMT');
header('Content-Type: text/html; charset=utf-8');
// MESSAGE TO SEND RETRIEVED FROM CONSOLE: $ php pvsnotifier.php "MY MESSAGE" [--twitter|--push]
$text = $argv[1];
//TwitterOAuth
$CONSUMER_KEY = "TWITER_CONSUMER_KEY";
$CONSUMER_SECRET = "TWITTER_CONSUMER_SECRET";
$ACCESS_TOKEN = "TWITTER_ACCESS_TOKEN";
$TOKEN_SECRET = "TWITTER_ACCESS_TOKEN_SECRET";
$twitter_user = "YOUR PRIMARY TWITTER USER";
// Pushover
$app_token = "PUSHOVER_APP_TOKEN";
$user_key = "PUSHOVER_USER_KEY";
function pushover(){
global $app_token, $user_key, $text;
// Send Pushover Notification
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => $app_token,
"user" => $user_key,
"message" => $text,
),
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_RETURNTRANSFER => true,
));
curl_exec($ch);
curl_close($ch);
}
function twitterDM(){
global $CONSUMER_KEY, $CONSUMER_SECRET, $ACCESS_TOKEN, $TOKEN_SECRET, $text, $twitter_user;
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $ACCESS_TOKEN, $TOKEN_SECRET);
$connection->post('direct_messages/new', array('text' => $text, 'screen_name' => $twitter_user));
}
// Send Twitter DM Notification system
if( isset($argv[2]) && $argv[2] == "--twitter"){
twitterDM();
}
// Else if pushover system
elseif( isset($argv[2]) && $argv[2] == "--push"){
pushover();
}
// else both notification systems
else
{
pushover();
twitterDM();
}
?>