/
charts.php
38 lines (28 loc) · 1.02 KB
/
charts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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>";
}