Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \Log::info('Fetch tweets');
     $client = new Client('https://api.twitter.com/1.1/');
     $auth = new Oauth(['consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'), 'token' => env('TWITTER_ACCESS_TOKEN'), 'token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET')]);
     $client->addSubscriber($auth);
     //$response = $client->get('search/tweets.json?q=%23peukpoll&since=' . date('Y-m-d'))->send();
     $response = $client->get('search/tweets.json?q=%23peukpoll')->send();
     $data = $response->json()['statuses'];
     $tweets = array_fetch($response->json()['statuses'], 'text');
     foreach ($tweets as $tweet) {
         $values[] = explode(' ', $tweet);
     }
     for ($i = 0; $i < count($values); $i++) {
         $user = User::where('username', $data[$i]['user']['screen_name'])->first();
         if ($user == null) {
             $user = new User();
             $user->username = $data[$i]['user']['screen_name'];
             $user->save();
         }
         $tweet = Tweet::where('tweet', $data[$i]['id'])->first();
         if ($tweet == null) {
             $tweet = new Tweet();
             $tweet->x = $values[$i][0];
             $tweet->y = $values[$i][2];
             $tweet->score_x = 1;
             $tweet->score_y = 1;
             $tweet->tweet = $data[$i]['id'];
             $tweet->user()->associate($user);
             $tweet->save();
             $numberOfUpcomingTweets = UpcomingTweet::all()->count();
             if ($numberOfUpcomingTweets > 0) {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 year'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             } else {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             }
         }
     }
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \Log::alert('Refresh tweets');
     $tweet = UpcomingTweet::where('end', '<', date('Y-m-d H:i:s'))->first();
     if ($tweet != null) {
         $tweet->delete();
         $newTweet = UpcomingTweet::orderBy('id', 'asc')->first();
         $newTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
         $newTweet->save();
     }
 }
Example #3
0
 public function getLatestVotes(Request $request)
 {
     $tweet = UpcomingTweet::first()->tweet;
     return response()->json($tweet);
 }
Example #4
0
 public function getDeleteTweet($id)
 {
     $tweet = UpcomingTweet::find($id);
     if ($tweet != null) {
         $tweet->delete();
     }
     return redirect()->route('admin');
 }