Skip to content

Instantly share code, notes, and snippets.

@shahrilnet
Created May 3, 2018 16:25
Show Gist options
  • Select an option

  • Save shahrilnet/dab7e6978732a14e9e526cfecdd4b984 to your computer and use it in GitHub Desktop.

Select an option

Save shahrilnet/dab7e6978732a14e9e526cfecdd4b984 to your computer and use it in GitHub Desktop.
Twitter's tweet live counter (works as 4-may-2018)
<?php
$link = "https://twitter.com/memanskywalker/status/991649182090903552";
$headers = [
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language: en-US,en;q=0.5",
"Cache-Control: no-cache",
"Connection: keep-alive",
"DNT: 1",
"Host: twitter.com",
"Pragma: no-cache",
"Upgrade-Insecure-Requests: 1",
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$data = trim(curl_exec($ch));
curl_close($ch);
preg_match('/<strong>(.*?)<\/strong> Retweets/', $data, $retweet_count);
preg_match('/<strong>(.*?)<\/strong> Likes/', $data, $like_count);
echo(json_encode([$retweet_count[1], $like_count[1]]));
?>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script>
setInterval(function() {
$.get( "api.php", function( data ) {
var obj = JSON.parse(data);
retweet = parseInt(obj[0].replace(/,/g, ''));
if (retweet >= 10000) {
$('.additional_msg').text("10k is real boisss...");
}
$('.retweet_data').text("Retweets : " + obj[0]);
$('.likes_data').text("Likes : " + obj[1]);
});
}, 1000);
</script>
<style>
.centered {
position: fixed;
top: 50%;
left: 50%;
font-size: 30px;
/* bring your own prefixes */
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class='centered'>
<center>
<img src="https://i.imgur.com/sRt6SNJ.jpg" width="250" height="300" />
<br>
<h1>Deng femes!!!</h1><br>
<h1 class='additional_msg'></h1><br>
<h1 class='retweet_data'></h1>
<h1 class='likes_data'></h1>
</center>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment