-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBotDuCul.php
More file actions
69 lines (56 loc) · 1.99 KB
/
BotDuCul.php
File metadata and controls
69 lines (56 loc) · 1.99 KB
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
<?php
include('../safeTweet.php');
include('dbinfo.php');
include('twitterCredentials.php');
require_once('../TwitterAPIExchange.php');
header('Content-Type: text/html; charset=utf-8');
/** Set access tokens here - see: https://apps.twitter.com/ **/
$APIsettings = array(
'oauth_access_token' => $oauthToken,
'oauth_access_token_secret' => $oauthTokenSecret,
'consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret
);
// Connect to applications DB
try {
$bddApp = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbAppName, $dbAppLogin, $dbAppPassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$bddApp->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
echo 'Echec de la connexion : ' . $e->getMessage();
exit;
}
$appResponse = $bddApp->query("SELECT value FROM misc WHERE appName='botDuCul'");
$appResult = $appResponse->fetchAll();
$wordid = $appResult[0][0];
$appResponse->closeCursor();
if($wordid < 46209){
try {
$bdd = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname, $dblogin, $dbpassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$bdd->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
echo 'Echec de la connexion : ' . $e->getMessage();
exit;
}
$queryWord = "SELECT DISTINCT lemme FROM lexique2 LIMIT 1 OFFSET " . $wordid;
$response = $bdd->query($queryWord);
$result = $response->fetchAll();
$word = $result[0][0];
$response->closeCursor();
$tweet = $word . " du cul";
$appResponse = $bddApp->query("UPDATE misc SET value = value + 1 WHERE appName = 'botDuCul'");
$appResponse->closeCursor();
if(safeTweet($tweet)){
// Post the tweet
$postfields = array(
'status' => $tweet);
$url = "https://api.twitter.com/1.1/statuses/update.json";
$requestMethod = "POST";
$twitter = new TwitterAPIExchange($APIsettings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
}else{
file_get_contents("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
}
?>