Exemplo n.º 1
0
<?php

require_once 'lib/datastore.class.php';
require_once 'lib/datafetcher.class.php';
$store = new DataStore();
$fetcher = new DataFetcher();
$user = $_GET['user'];
if (!$user) {
    die("No user specified.");
}
$scrobbles = $store->getAllScrobbles($user);
$chart = array();
foreach ($scrobbles as $scrobble) {
    $address = $fetcher->fetchAddress($scrobble['latitude'] . ',' . $scrobble['longitude']);
    $address = preg_replace('/London.*?,/', 'London,', $address);
    if (!isset($chart[$address])) {
        $chart[$address] = array();
    }
    if (!isset($chart[$address][$scrobble['artist']])) {
        $chart[$address][$scrobble['artist']] = 0;
    }
    $chart[$address][$scrobble['artist']]++;
}
foreach ($chart as $place => $chart) {
    arsort($chart);
    print "<h4>{$place}</h4><ul>";
    foreach ($chart as $artist => $plays) {
        print "<li><b>{$plays}</b>. {$artist}</li>";
    }
    print "</ul><br>";
}
Exemplo n.º 2
0
    
    <h1>Listening Locations</h1>
    <b>Last.fm username:</b>
    <form>
        <input type="text" name="user">
        <input type="submit" value="To google, and beyond!">
    </form>
    <small>
        You need to have a google latitude listening history for this to work.
        <a href="http://wiki.musichackday.org/index.php?title=ListeningLocations">Find out more.
    </small>
    
    <?php 
    exit;
}
$fetcher = new DataFetcher();
$oauth = new OAuthFetcher();
// This will do the OAuth bounce handshake dance.
$fetchTimestamp = $foundScrobbles = null;
$lastTimestamp = time() * 1000;
while ($fetchTimestamp != $lastTimestamp) {
    $fetchTimestamp = $lastTimestamp;
    try {
        $queryString = http_build_query(array('max-results' => 1000, 'max-time' => $fetchTimestamp, 'granularity' => 'best'));
        $apiUrl = 'https://www.googleapis.com/latitude/v1';
        $oauth->fetch("{$apiUrl}/location?{$queryString}");
    } catch (OAuthException $e) {
        trigger_error("OAuth fail: " . print_r($e, true));
        ?>
        Something failed during the OAuth data fetch from google! 
        Are you sure you have <a href='https://www.google.com/latitude/history'>Google Latitude location history</a> enabled?