Esempio n. 1
0
 public function google()
 {
     $google = new GoogleAPI();
     $states = Location::states;
     $donePresident = false;
     foreach ($states as $state_abbrev => $state_name) {
         echo "state: " . $state_name . "\n";
         $req = $google->address($state_name)->then(function ($data) use($donePresident) {
             foreach ($data->reps as $rep) {
                 if ($rep->office == 'President' && !$donePresident) {
                     unset($rep->state);
                     $rep->save();
                     $donePresident = true;
                 } else {
                     if (Representative::exists($rep)) {
                         $old = Representative::find($rep);
                         foreach ($rep->getAttributes() as $k => $v) {
                             if (!empty($v)) {
                                 $old->{$k} = $v;
                             }
                         }
                         $old->save();
                     } else {
                         if ($rep->office == 'Governor') {
                             $rep->save();
                         }
                     }
                 }
             }
         });
         $req->wait();
     }
 }