From 06b84c1ec79256fe0605febbd5fc23356329cf95 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 7 Jul 2017 16:41:24 -0700 Subject: [PATCH] store geo data from tweets --- app/Http/Controllers/ImportController.php | 2 ++ app/Http/Controllers/TwitterController.php | 4 +++ app/Tweet.php | 3 +- .../2017_07_07_233528_tweet_geo.php | 34 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2017_07_07_233528_tweet_geo.php diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index e7f9f36..d44dab4 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -110,6 +110,8 @@ class ImportController extends BaseController $tweet->photo = json_encode($photos, JSON_UNESCAPED_SLASHES); $tweet->mission_id = $mission_id; $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data->created_at)); + $tweet->geo = json_encode($data->geo); + $tweet->place = json_encode($data->place); return $tweet; } diff --git a/app/Http/Controllers/TwitterController.php b/app/Http/Controllers/TwitterController.php index 8e050c8..bf4f4c3 100644 --- a/app/Http/Controllers/TwitterController.php +++ b/app/Http/Controllers/TwitterController.php @@ -57,6 +57,10 @@ class TwitterController extends BaseController $tweet->photo = json_encode($photos, JSON_UNESCAPED_SLASHES); $tweet->mission_id = $mission_id; $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at'])); + if(isset($data['geo'])) + $tweet->geo = json_encode($data['geo']); + if(isset($data['place'])) + $tweet->place = json_encode($data['place']); $tweet->save(); if($tweet->mission_id && $tweet->team_id) { diff --git a/app/Tweet.php b/app/Tweet.php index bed14dc..8d72df2 100644 --- a/app/Tweet.php +++ b/app/Tweet.php @@ -13,7 +13,8 @@ class Tweet extends Model 'm1_transit_line_id', 'm1_non_trimet', 'm2_transit_center_id', 'm2_with_other_team', 'm3_complete', 'm4_complete', 'm5_complete', 'm5_tip', - 'm6_complete', 'm7_document_id' + 'm6_complete', 'm7_document_id', + 'geo', 'place' ]; public function team() { diff --git a/database/migrations/2017_07_07_233528_tweet_geo.php b/database/migrations/2017_07_07_233528_tweet_geo.php new file mode 100644 index 0000000..ed63a17 --- /dev/null +++ b/database/migrations/2017_07_07_233528_tweet_geo.php @@ -0,0 +1,34 @@ +text('geo')->nullable(); + $table->text('place')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tweets', function (Blueprint $table) { + $table->dropColumn('geo'); + $table->dropColumn('place'); + }); + } +}