-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweets.php
124 lines (115 loc) · 3.35 KB
/
tweets.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
<?php
require_once ('phirehose/lib/Phirehose.php');
require_once ('phirehose/lib/OauthPhirehose.php');
/**
* Example of using Phirehose to display a live filtered stream using track words
*/
class FilterTrackConsumer extends OauthPhirehose {
private $tweet_count = 0;
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status) {
/*
* In this simple example, we will just display to STDOUT rather than enqueue. NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being enqueued and processed asyncronously from the collection process.
*/
$data = json_decode ( $status, true );
if (is_array ( $data ) && isset ( $data ['user'] ['screen_name'] )) {
$date = explode ( " ", $data ['created_at'] );
$heure = explode ( ":", $date [3] );
switch ($date [1]) {
case "Jan" :
$mois = "01";
break;
case "Feb" :
$mois = "02";
break;
case "Mar" :
$mois = "03";
break;
case "Apr" :
$mois = "04";
break;
case "May" :
$mois = "05";
break;
case "Jun" :
$mois = "06";
break;
case "Jul" :
$mois = "07";
break;
case "Aug" :
$mois = "08";
break;
case "Sep" :
$mois = "09";
break;
case "Oct" :
$mois = "10";
break;
case "Nov" :
$mois = "11";
break;
default :
$mois = "12";
break;
}
$date_r = $date [5] . "-" . $mois . "-" . $date [2];
$text = $data ['text'];
/*
* $substr = explode ( " ", $text ); foreach ( $substr as $http ) { if (strstr ( $http, "http" )) { $link = "<a href=\"" . $http . "\">" . $http . "</a><BR/>"; $text = str_replace ( $http, $link, $text ); } }
*/
$localisation = "";
if (! empty ( $data ['user'] ['location'] )) {
$localisation = $data ['user'] ['location'];
}
$this->tweet_count += 1;
$mots_cles="";
$substr = explode ( " ", $text );
foreach ( $substr as $word ) {
foreach($this->getTrack() as $motcle)
if ($word==$motcle) {
$mots_cles=$word;
}
}
try {
include ('connect.inc.php');
$req = $bdd->prepare ( "INSERT into tweet(message, localisation, date, mots_cles) values (:message, :localisation, :date, :mots_cles);" );
$ok = $req->execute ( array (
'message' => $text,
'localisation' => $localisation,
'date' => $date_r,
'mots_cles' => $mots_cles
) );
} catch ( PDOException $e ) {
echo "<BR/>" . $e . "<BR/>";
}
}
if ($this->tweet_count >= 5) {
exit ();
}
}
}
// The OAuth credentials you received when registering your app at Twitter
define ( "TWITTER_CONSUMER_KEY", "fxPiWdMXW0oHk9OLwIavMn3ns" );
define ( "TWITTER_CONSUMER_SECRET", "eCRPfxT3bRG490KWPcbpO6F1RX4FdXCW8c9HquFxOCsCTP2dPH" );
// The OAuth data for the twitter account
define ( "OAUTH_TOKEN", "763684332-g2P4tnD0xlXzwOc4cZFILrPkIUXOuU5PTiXMD2S6" );
define ( "OAUTH_SECRET", "sIFafoYoFchI8KF4i3QSOXPzvi4L63lvnv2HRTtnz8pQP" );
// Start streaming
$sc = new FilterTrackConsumer ( OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER );
$sc->setTrack ( array (
'#attentat',
'#catastrophe',
'#désastre',
'#alerte',
'#secours',
'#accident',
'#rip',
'#sos'
) );
$sc->consume ();
?>