-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
64 lines (47 loc) · 1.05 KB
/
cron.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
<?php
/**
* Created by PhpStorm.
* User: Nemanja
* Date: 27.2.2017
* Time: 20:21
*/
/*
* Require initialization file
*/
require "config/init.php";
global $config;
use Abraham\TwitterOAuth\TwitterOAuth;
/*
* Instances
*/
$tweets = new Tweets();
/*
* Config
*/
$confTwitter = $config['twitter'];
$lastStoredTweetId = $tweets->getLastTweetId();
/*
* Twitter Api Options
*/
if ( $lastStoredTweetId ) {
$options = [
'since_id' => $lastStoredTweetId,
'screen_name' => $confTwitter['screen_name']
];
} else {
$options = [
'count' => 100,
'screen_name' => $confTwitter['screen_name']
];
}
$connection = new TwitterOAuth($confTwitter['consumer_key'], $confTwitter['consumer_secret'], $confTwitter['access_token'], $confTwitter['access_secret']);
$content = $connection->get("statuses/user_timeline", $options);
/*
* Store whole response
*/
$totalStored = $tweets->storeTweets($content);
if ($totalStored > 0) {
echo "Stored {$totalStored} new tweets in DB!";
} else {
echo "It's already updated!";
}