-
Notifications
You must be signed in to change notification settings - Fork 1k
/
TwitScoopBridge.php
155 lines (137 loc) · 5.16 KB
/
TwitScoopBridge.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
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 = [
[
'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',
]
],
'limit' => [
'name' => 'Topics',
'type' => 'number',
'title' => 'Number of trending topics to return. Max 50',
'defaultValue' => 20,
]
]
];
const CACHE_TIMEOUT = 900; // 15 mins
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
$updated = $html->find('time', 0)->datetime;
$trends = $html->find('div.trends', 0);
$limit = $this->getInput('limit');
if ($limit > 50 || $limit < 1) {
$limit = 50;
}
foreach ($trends->find('ol.items > li') as $index => $li) {
$number = $index + 1;
$item = [];
$name = rtrim($li->find('span.trend.name', 0)->plaintext, ' ');
$tweets = str_replace(' tweets', '', $li->find('span.tweets', 0)->plaintext);
$tweets = str_replace('<', '', $tweets);
$item['title'] = '#' . $number . ' - ' . $name . ' (' . $tweets . ' tweets)';
$item['uri'] = 'https://twitter.com/search?q=' . rawurlencode($name);
if ($tweets === '10K') {
$tweets = 'less than 10K';
}
$item['content'] = <<<EOD
<strong>Rank</strong><br>
<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) {
break;
}
}
}
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'))) {
return $this->getKey('country') . ' - TwitScoop';
}
return parent::getName();
}
}