2021-03-15 19:20:02 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
class TwitScoopBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'TwitScoop Bridge';
|
|
|
|
const URI = 'https://www.twitscoop.com';
|
|
|
|
const DESCRIPTION = 'Returns trending Twitter topics by country';
|
|
|
|
const MAINTAINER = 'VerifiedJoseph';
|
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2021-03-15 19:20:02 +03:00
|
|
|
'country' => [
|
|
|
|
'name' => 'Country',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Worldwide' => 'worldwide',
|
|
|
|
'Algeria' => 'algeria',
|
|
|
|
'Argentina' => 'argentina',
|
|
|
|
'Australia' => 'australia',
|
|
|
|
'Austria' => 'austria',
|
|
|
|
'Bahrain' => 'bahrain',
|
|
|
|
'Belarus' => 'belarus',
|
|
|
|
'Belgium' => 'belgium',
|
|
|
|
'Brazil' => 'brazil',
|
|
|
|
'Canada' => 'canada',
|
|
|
|
'Chile' => 'chile',
|
|
|
|
'Colombia' => 'colombia',
|
|
|
|
'Denmark' => 'denmark',
|
|
|
|
'Dominican Republic' => 'dominican-republic',
|
|
|
|
'Ecuador' => 'ecuador',
|
|
|
|
'Egypt' => 'egypt',
|
|
|
|
'France' => 'france',
|
|
|
|
'Germany' => 'germany',
|
|
|
|
'Ghana' => 'ghana',
|
|
|
|
'Greece' => 'greece',
|
|
|
|
'Guatemala' => 'guatemala',
|
|
|
|
'India' => 'india',
|
|
|
|
'Indonesia' => 'indonesia',
|
|
|
|
'Ireland' => 'ireland',
|
|
|
|
'Israel' => 'israel',
|
|
|
|
'Italy' => 'italy',
|
|
|
|
'Japan' => 'japan',
|
|
|
|
'Jordan' => 'jordan',
|
|
|
|
'Kenya' => 'kenya',
|
|
|
|
'Korea' => 'korea',
|
|
|
|
'Kuwait' => 'kuwait',
|
|
|
|
'Latvia' => 'latvia',
|
|
|
|
'Lebanon' => 'lebanon',
|
|
|
|
'Malaysia' => 'malaysia',
|
|
|
|
'Mexico' => 'mexico',
|
|
|
|
'Netherlands' => 'netherlands',
|
|
|
|
'New Zealand' => 'new-zealand',
|
|
|
|
'Nigeria' => 'nigeria',
|
|
|
|
'Norway' => 'norway',
|
|
|
|
'Oman' => 'oman',
|
|
|
|
'Pakistan' => 'pakistan',
|
|
|
|
'Panama' => 'panama',
|
|
|
|
'Peru' => 'peru',
|
|
|
|
'Philippines' => 'philippines',
|
|
|
|
'Poland' => 'poland',
|
|
|
|
'Portugal' => 'portugal',
|
|
|
|
'Puerto Rico' => 'puerto-rico',
|
|
|
|
'Qatar' => 'qatar',
|
|
|
|
'Russia' => 'russia',
|
|
|
|
'Saudi Arabia' => 'saudi-arabia',
|
|
|
|
'Singapore' => 'singapore',
|
|
|
|
'South Africa' => 'south-africa',
|
|
|
|
'Spain' => 'spain',
|
|
|
|
'Sweden' => 'sweden',
|
|
|
|
'Switzerland' => 'switzerland',
|
|
|
|
'Thailand' => 'thailand',
|
|
|
|
'Turkey' => 'turkey',
|
|
|
|
'Ukraine' => 'ukraine',
|
|
|
|
'United Arab Emirates' => 'united-arab-emirates',
|
|
|
|
'United Kingdom' => 'united-kingdom',
|
|
|
|
'United States' => 'united-states',
|
|
|
|
'Venezuela' => 'venezuela',
|
|
|
|
'Vietnam' => 'vietnam',
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2021-03-15 19:20:02 +03:00
|
|
|
],
|
|
|
|
'limit' => [
|
|
|
|
'name' => 'Topics',
|
|
|
|
'type' => 'number',
|
|
|
|
'title' => 'Number of trending topics to return. Max 50',
|
|
|
|
'defaultValue' => 20,
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2021-03-15 19:20:02 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
const CACHE_TIMEOUT = 900; // 15 mins
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
$updated = $html->find('time', 0)->datetime;
|
|
|
|
$trends = $html->find('div.trends', 0);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
$limit = $this->getInput('limit');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
if ($limit > 50 || $limit < 1) {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
foreach ($trends->find('ol.items > li') as $index => $li) {
|
|
|
|
$number = $index + 1;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
$name = rtrim($li->find('span.trend.name', 0)->plaintext, ' ');
|
|
|
|
$tweets = str_replace(' tweets', '', $li->find('span.tweets', 0)->plaintext);
|
2021-04-12 21:01:46 +03:00
|
|
|
$tweets = str_replace('<', '', $tweets);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-21 09:39:01 +03:00
|
|
|
$item['title'] = '#' . $number . ' - ' . $name . ' (' . $tweets . ' tweets)';
|
2021-03-15 19:20:02 +03:00
|
|
|
$item['uri'] = 'https://twitter.com/search?q=' . rawurlencode($name);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-04-12 21:01:46 +03:00
|
|
|
if ($tweets === '10K') {
|
|
|
|
$tweets = 'less than 10K';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-03-15 19:20:02 +03:00
|
|
|
$item['content'] = <<<EOD
|
2021-03-21 09:39:01 +03:00
|
|
|
<strong>Rank</strong><br>
|
2021-03-15 19:20:02 +03:00
|
|
|
<p>{$number}</p>
|
|
|
|
<Strong>Topic</strong><br>
|
|
|
|
<p>{$name}</p>
|
|
|
|
<Strong>Tweets</strong><br>
|
|
|
|
<p>{$tweets}</p>
|
|
|
|
EOD;
|
|
|
|
$item['timestamp'] = $updated;
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
|
|
|
|
if (count($this->items) >= $limit) {
|
2022-07-01 16:10:30 +03:00
|
|
|
break;
|
2021-03-15 19:20:02 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2021-03-15 19:20:02 +03:00
|
|
|
|
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('country'))) {
|
|
|
|
return self::URI . '/' . $this->getInput('country');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('country'))) {
|
2023-03-06 22:01:51 +03:00
|
|
|
return $this->getKey('country') . ' - TwitScoop';
|
2021-03-15 19:20:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
}
|