Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Abraham\TwitterOAuth\TwitterOAuth;
- use App\Tweet;
- class ImportTweets extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'import:tweets {account}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $account = str_replace('@', '', $this->argument('account'));
- $tweets = \App\Services\Twitter\TwitterService::getTweetsByUser($account, 50);
- foreach ($tweets as $tweet)
- {
- $this->createTweet($tweet);
- }
- }
- private function createTweet($tweet)
- {
- $newTweet = new Tweet();
- $newTweet->content = $tweet->text;
- $newTweet->tweet_created_at = date('Y-m-d H:i:s', strtotime($tweet->created_at));
- $newTweet->likes = $tweet->favorite_count;
- $newTweet->retweets = $tweet->retweet_count;
- if($tweet->coordinates !== null)
- {
- $newTweet->latitude = $tweet->coordinates->coordinates[0];
- $newTweet->longitude = $tweet->coordinates->coordinates[1];
- }
- $newTweet->user = $tweet->user->screen_name;
- $newTweet->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement