Exemple #1
0
 public function run()
 {
     $FoursquareClient = new \Foursquare\Client();
     $file_content = File::read(DOCROOT . 'data/NY.csv', true);
     $data = Format::forge($file_content, 'csv')->to_array();
     $valid_counties = array();
     $valid_counties[] = 'BRONX';
     $valid_counties[] = 'QUEENS';
     $valid_counties[] = 'KINGS';
     $valid_counties[] = 'NEW YORK';
     $valid_counties[] = 'RICHMOND';
     $i = 0;
     $j = 0;
     foreach ($data as $key => $value) {
         if (!in_array($value['County'], $valid_counties)) {
             continue;
         }
         $i++;
         if ($i > 300) {
             break;
         }
         $match = $FoursquareClient->getVenueMapping($value['Latitude'], $value['Longitude'], $value['Store_Name']);
         if ($this->hasMatches($match, &$j)) {
             $this->logMatches($value, $match, $matches, $j, $i);
             continue;
         }
         $this->CliOutput('write', 'Stripping chars from Store_Name: ' . $value['Store_Name']);
         // remove numbers from store name
         $value['Store_Name'] = trim(preg_replace("/[0-9]/", "", $value['Store_Name']));
         $match = $FoursquareClient->getVenueMapping($value['Latitude'], $value['Longitude'], $value['Store_Name']);
         if ($this->hasMatches($match, &$j)) {
             $this->logMatches($value, $match, $matches, $j, $i);
             continue;
         }
         $this->CliOutput('error', 'No match for ' . $value['Store_Name'] . ' ' . $value['Address'] . ' ' . $value['City'] . ' ' . $value['Zip5']);
     }
     $this->CliOutput('write', 'Matches: ' . $j . '/' . $i);
 }
Exemple #2
0
 public function updateVenues()
 {
     $locationsUpdated = 0;
     $empty_responses = 0;
     $FoursquareClient = new \Foursquare\Client();
     $tracking_logs = \Collection\Tracking_Log::getQueuedItems('foursquare');
     if ($tracking_logs->count() == 0) {
         $this->cliOutput('error', 'Nothing to scan!??? Waiting for 5 minutes.');
         $this->cliOutput('wait', 300);
     }
     // a bunch of foursquare location IDs
     $groupedObjects = \Collection\Mixed::convertObjectIds($tracking_logs);
     foreach ($groupedObjects as $table => $groupedObjectIds) {
         switch ($table) {
             case 'venue':
                 // foursquare: it's possible to make a batch request containing 5 venue IDs
                 $ids = array_chunk($groupedObjectIds, 5, true);
                 foreach ($ids as $venue_ids) {
                     $locations = $FoursquareClient->getVenueInfoBatch($venue_ids);
                     // print_r($locations);
                     // exit;
                     if (!isset($locations->response->responses[0]->meta->code) && $locations->response->responses[0]->meta->code == 403) {
                         $this->cliOutput('error', 'Failure: rate_limit_exceeded Quota exceeded');
                         return;
                     }
                     if (!isset($locations->response->responses)) {
                         $this->cliOutput('error', 'Warning: Empty response (1)');
                         $empty_responses++;
                         if ($empty_responses > 3) {
                             // $this->cliOutput('error', 'Failure: rate_limit_exceeded Quota exceeded');
                             // print_r($venue);
                             // exit;
                         }
                         continue;
                     }
                     foreach ($locations->response->responses as $key => $venue) {
                         if (!isset($venue->response->venue)) {
                             $this->cliOutput('error', 'Warning: Empty response (2)');
                             $empty_responses++;
                             if ($empty_responses > 3) {
                                 // print_r($venue);
                                 // exit;
                                 return false;
                             }
                             continue;
                         }
                         $system_venue_id = array_search($venue->response->venue->id, $venue_ids);
                         if (!$system_venue_id) {
                             $this->cliOutput('error', 'Failure: Unable to get venue ID: ' . $venue->response->venue->id);
                             $this->cliOutput('error', 'IDs: ' . print_r($groupedObjects));
                             // $empty_responses++;
                             // if($empty_responses > 3) {
                             // print_r($venue);
                             // exit;
                             // }
                             continue;
                         }
                         $stats = \Collection\Venue::saveVenueStats($system_venue_id, $venue->response->venue, true);
                         \Collection\Venue::createOrUpdateVenueMetaFoursquare($system_venue_id, $venue->response->venue);
                         if (!is_array($stats)) {
                             $this->CliOutput('error', 'Failure: ' . $stats);
                             continue;
                         }
                         $this->debugMessage('Updated: ' . $venue->response->venue->name . ' / ' . $venue->response->venue->id);
                         $this->debugMessage('Stats: ' . implode(', ', $stats));
                         $locationsUpdated++;
                     }
                 }
                 break;
             default:
                 break;
         }
     }
     $this->emailReport('Locations updated: ' . $locationsUpdated);
     return true;
     // echo \DB::last_query();
 }
Exemple #3
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::controller('/twit', "TwitterController");
Route::get('can', function () {
    $fs = new \Foursquare\Client();
    $checkins = $fs->api('checkins')->recent();
    // recent($id,max=10)
    foreach ($checkins as $checkin) {
        echo $checkin;
        // $checkin->timestamp.' '.$checkin->getVenue()->getName()
    }
});