Skip to content

Instantly share code, notes, and snippets.

@brianherbert
Created June 19, 2018 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianherbert/e62d80a0888b8a019c04ed7efd1d7252 to your computer and use it in GitHub Desktop.
Save brianherbert/e62d80a0888b8a019c04ed7efd1d7252 to your computer and use it in GitHub Desktop.
<?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