-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
176 lines (155 loc) · 5.46 KB
/
index.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/1.0.6/css/dataTables.responsive.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/responsive/1.0.6/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#tabela1').DataTable({
language: {
url: "https://cdn.datatables.net/plug-ins/1.10.7/i18n/Portuguese-Brasil.json",
},
// paging: false,
searching: false,
ordering: false,
}); // datatables
$('#tabela2').DataTable({
language: {
url: "https://cdn.datatables.net/plug-ins/1.10.7/i18n/Portuguese-Brasil.json",
},
// paging: false,
searching: false,
ordering: false,
}); // datatables
$('#tabela3').DataTable({
language: {
url: "https://cdn.datatables.net/plug-ins/1.10.7/i18n/Portuguese-Brasil.json",
},
// paging: false,
searching: false,
ordering: false,
}); // datatables
});
</script>
<style type="text/css">
table.dataTable th,
table.dataTable td {
white-space: nowrap;
}
div {
margin-left: 10px;
width: 99%
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<?php
require ("twitteroauth/autoload.php");
use Abraham\TwitterOAuth\TwitterOAuth;
define("CONSUMER_KEY", "Vy3EeNMvboZbFro66GQrKpPGi");
define("CONSUMER_SECRET", "sxrLnQ77UQ7wBHVVxlQ37uSVsuMEXCWVwU4UGITleeymopraAl");
// include 'twitteroauth/src/TwitterOAuth.php';
// use Abraham\TwitterOAuth\TwitterOAuth;
function search($string, $count, $type) {
$access_token = "3227234898-oMKzM9SSY9aE5I4viIisGZ58mQJceIPn6KhCiS9";
$access_token_secret = "xHN3fYrkGAiNgSowvxigh1mMLXfegDtozP04f0s1ODRT1";
$connection = new TwitterOAuth(
CONSUMER_KEY,
CONSUMER_SECRET,
$access_token,
$access_token_secret
);
$content = $connection->get("account/verify_credentials");
// var_dump($content);
$statuses = $connection->get("search/tweets", array(
"lang" => "pt",
"q" => $string,
"count" => "20",
"result_type" => $type
));
// var_dump($statuses);
// echo '<pre>'; print_r($statuses); echo '</pre>';
return $statuses;
}
function blackList($tokens, $list) {
return array_diff($tokens, $list);
}
function most_common($most_common, $tokens) {
foreach ($tokens as $token) {
if (isset($most_common[$token])) {
$most_common[$token]++;
}else{
$most_common[$token] = 1;
}
}
return $most_common;
}
function most_common_user($most_common_user, $users) {
foreach ($users as $user) {
if (isset($most_common_user[$user])) {
$most_common_user[$user]++;
}else{
$most_common_user[$user] = 1;
}
}
return $most_common_user;
}
function pprint($result, $table, $list) {
$most_common = array();
$most_common_user = array();
$users = array();
echo "<div><table id='". $table ."' class='table table-striped table-hover dt-responsive'
cellspacing='0' width='100%'><thead><tr><th>Usuário</th><th class='desktop'>
Tweet</th></tr></thead><tbody>";
foreach ($result->statuses as $singleResult) {
$tokens = explode(' ', $singleResult->text);
$tokens = blackList($tokens, $list);
echo "<tr>
<td><a href='http://twitter.com/" . $singleResult->user->screen_name . "'><img src='" .
$singleResult->user->profile_image_url . "' alt='perfil'/> " .
$singleResult->user->screen_name ."</a></td>
<td>" . implode(' ', $tokens) . "</td>
</tr>";
$most_common = most_common($most_common, $tokens);
array_push($users, $singleResult->user->screen_name);
$most_common_user = most_common_user($most_common_user, $users);
}
echo "</tbody></table></div><br/><hr><br/>";
arsort($most_common);
echo "<h3>Palavras mais citadas:</h3>";
echo "<ul>";
foreach ($most_common as $key => $val) {
echo "<li>$key = $val</li>";
}
echo "</ul>";
arsort($most_common_user);
echo "<h3>Usuários que mais escreveram:</h3>";
echo "<ul>";
foreach ($most_common_user as $key => $val) {
echo "<li>$key = $val</li>";
}
echo "</ul>";
}
$list = array("é", "e", "te", "me", "um", "uma", "no", "RT", "a");
echo "<h2>Lava Jato</h2>";
$result = search("Lava jato", "5", "popular");
pprint($result, "tabela1", $list);
echo "<h2>#ForaPT</h2>";
$result2 = search("#forapt", "5", "recent");
pprint($result2, "tabela2", $list);
echo "<h2>#E32015 Batman</h2>";
$result3 = search("#e32015 batman", "5", "recent");
pprint($result3, "tabela3", $list);
?>
</body>
</html>