Created
June 19, 2018 18:42
-
-
Save brianherbert/e62d80a0888b8a019c04ed7efd1d7252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const SLACK_TOKEN = ''; | |
const SLACK_CHANNEL = '#worldcup'; | |
const SLACK_BOT_NAME = 'World Cup'; | |
const SLACK_BOT_AVATAR = 'https://i.imgur.com/Pd0cpqE.png'; | |
function curl_get($url) { | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => $url, | |
CURLOPT_USERAGENT => 'cURL Request' | |
)); | |
$response = curl_exec($curl); | |
curl_close($curl); | |
return json_decode($response); | |
} | |
function post_to_slack($text, $attachments_text = '') | |
{ | |
$slackUrl = 'https://slack.com/api/chat.postMessage?token='.SLACK_TOKEN. | |
'&channel='.urlencode(SLACK_CHANNEL). | |
'&username='.urlencode(SLACK_BOT_NAME). | |
'&icon_url='.SLACK_BOT_AVATAR. | |
'&unfurl_media=true&unfurl_links=true&parse=full&pretty=1'. | |
'&text='.urlencode($text); | |
if ($attachments_text) | |
{ | |
$slackUrl .= '&attachments='.urlencode('[{"text": "'.$attachments_text.'"}]'); | |
} | |
$response = curl_get($slackUrl); | |
//var_dump($response); | |
} | |
$file = __DIR__ . DIRECTORY_SEPARATOR .'posted_timestamps.txt'; | |
if(!is_file($file)){ | |
$contents = "0\n"; | |
file_put_contents($file, $contents); | |
} | |
$timestamps = file_get_contents($file); | |
$url = 'https://api.clippit.tv/api/v3/profiles/80881/clips/'; | |
$clips = curl_get($url); | |
foreach($clips->results AS $clip) { | |
$mpfour = $clip->video->SD; | |
$timestamp = $clip->time_created; | |
$thumbnail = $clip->thumbnail; | |
if(stripos($timestamps, (string)$timestamp)) { | |
// Already Posted This | |
continue; | |
} | |
$timestamps .= "\n$timestamp"; | |
file_put_contents($file, $timestamps); | |
echo $timestamp.": ".$thumbnail." Watch :movie_camera: ".$mpfour."\n"; | |
post_to_slack($thumbnail,"Watch :movie_camera: ".$mpfour); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment