forked from romulcah/tmr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.php
184 lines (119 loc) · 4.48 KB
/
twitter.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
177
178
179
180
181
182
183
184
<?php
$dw = date( "w", time() );
if($dw<0 && $dw>4){
"NO RANKINGS YET";
exit;
}
require "twitteroauth/autoload.php";
include("config.php");
include("db.php");
$database = new Database();
use Abraham\TwitterOAuth\TwitterOAuth;
$tweets = array();
function search(array $query)
{
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
return $toa->get('search/tweets', $query);
}
$query = array(
"q" => "@MatthewBerryTMR",
);
$results = search($query);
foreach ($results->statuses as $result) {
$matches = array();
$test = 0;
$pattern= "/(\w+\s){2}or(\s\w+){2}/";
$result->text = str_replace("CJ", "C.J.", $result->text);
$result->text = str_replace("cj", "C.J.", $result->text);
$subject= $result->text;
$test = preg_match($pattern, $subject, $matches);
$tweet_created=false;
//$result->text = str_replace("Steve Smith", "Steve Smith Sr.", $result->text);
//echo("... $matches[0] ...");
if($test==1){
$temp = explode(" or ",$matches[0]);
$name1 = $temp[0];
$name2 = $temp[1];
echo $temp[0];
echo $temp[1];
if(strpos(strtolower($result->text), 'ppr' )>0){
} else {
$database->query('SELECT * FROM rankings WHERE name = :name');
$database->bind(':name', $temp[0]);
$row = $database->single();
$player1 = $row;
print_r($player1);
$database->query('SELECT * FROM rankings WHERE name = :name');
$database->bind(':name', $temp[1]);
$row = $database->single();
$player2 = $row;
print_r($player2);
echo $result->text."<br />";
if(strlen($player1['name'])>5 && strlen($player2['name'])>5){
if($player1['position']==$player2['position']){
if($player1['rank']<$player2['rank']){
$tweet_temp['tweet_id'] = $result->id;
$tweet_temp['text'] = "@".$result->user->screen_name." Between ".$player1['name']." and ".$player2['name'].", start ".$player1['name']." per @MatthewBerryTMR rankings ".RANKINGS;
$tweet_created=true;
$tweets[]=$tweet_temp;
} elseif($player2['rank']<$player1['rank']) {
$tweet_temp['tweet_id'] = $result->id;
$tweet_temp['text'] = "@".$result->user->screen_name." Between ".$player1['name']." and ".$player2['name'].", start ".$player2['name']." per @MatthewBerryTMR rankings ".RANKINGS;
$tweets[]=$tweet_temp;
$tweet_created=true;
}
print_r($tweets);
}
}
}
}
if(!$tweet_created){
$pattern= "/(\w+\s){1}or(\s\w+){1}/";
$subject= $result->text;
$test = preg_match($pattern, $subject, $matches);
if($test==1){
$temp = explode(" or ",$matches[0]);
$name1 = $temp[0];
$name2 = $temp[1];
echo $temp[0];
echo $temp[1];
if(strpos(strtolower($result->text), 'ppr' )>0){
} else {
$database->query('SELECT * FROM rankings WHERE name like :name');
$database->bind(':name', "%".$temp[0]."%");
$row = $database->single();
$player1 = $row;
print_r($player1);
$database->query('SELECT * FROM rankings WHERE name like :name');
$database->bind(':name', "%".$temp[1]."%");
$row = $database->single();
$player2 = $row;
print_r($player2);
echo $result->text."<br />";
if(strlen($player1['name'])>5 && strlen($player2['name'])>5){
if($player1['position']==$player2['position']){
if($player1['rank']<$player2['rank']){
$tweet_temp['tweet_id'] = $result->id;
$tweet_temp['text'] = "@".$result->user->screen_name." Between ".$player1['name']." and ".$player2['name'].", start ".$player1['name']." per @MatthewBerryTMR rankings ".RANKINGS;
$tweets[]=$tweet_temp;
} elseif($player2['rank']<$player1['rank']) {
$tweet_temp['tweet_id'] = $result->id;
$tweet_temp['text'] = "@".$result->user->screen_name." Between ".$player1['name']." and ".$player2['name'].", start ".$player2['name']." per @MatthewBerryTMR rankings ".RANKINGS;
$tweets[]=$tweet_temp;
}
print_r($tweets);
}
}
}
}
}
}
$database->beginTransaction();
$database->query('INSERT IGNORE INTO tweets (tweet, tweet_id) VALUES (:tweet, :tweet_id)');
foreach($tweets as $tweet){
$database->bind(':tweet', $tweet['text']);
$database->bind(':tweet_id', $tweet['tweet_id']);
$database->execute();
}
$database->endTransaction();
?>