flickr api

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* by Nicolae Vartolomei <me@nvartolomei.com>
*
* Flickr crowler.
*/
set_time_limit(0);
ignore_user_abort(TRUE);
define("LIB_DIR", realpath(dirname(__FILE__) . "/../lib/"));
define("API_KEY", "nu va arat");
define("API_SECRET", "asta tot nu va arat");
require_once LIB_DIR . "/phpFlickr.php";
$flickr = new phpFlickr(API_KEY, API_SECRET);
$dbServer = mysql_connect("localhost", "nvartol_root", "nish asta nu va arat! :P");
mysql_select_db("nvartol_main", $dbServer);
/**
* Get id's
*/
$users = array();
$result = mysql_query("SELECT userId, flickrId FROM flickrUsers");
while($data = mysql_fetch_array($result)) {
$users[] = $data;
}
/**
* Get views
*/
$userCount = count($users);
for ($i = 0; $i < $userCount; $i++) {
$photos = $flickr->people_getPublicPhotos($users[$i]["flickrId"]);
$totalViews = 0;
foreach($photos['photos']['photo'] as $photo) {
$info = $flickr->photos_getInfo($photo['id']);
$totalViews += $info['views'];
}
$users[$i]["views"] = $totalViews;
}
/**
* Store stats in database
*/
for ($i = 0; $i < $userCount; $i++) {
$q = "INSERT INTO flickrVisits (userId, updatedAt, visits) VALUES('" . $users[$i]["userId"] . "', NOW(), '" . $users[$i]["views"] . "')";
mysql_query($q);
}