php by Nicolae Vartolomei me nvartolomei com Flickr crowler set_time_l

 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
<?php
/**
* by Nicolae Vartolomei <me@nvartolomei.com>
*
* Flickr crowler.
*/
set_time_limit(0);
ignore_user_abort(TRUE);
require_once "config.php";
require_once LIB_DIR . "/phpFlickr.php";
$flickr = new phpFlickr(API_KEY, API_SECRET);
$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;
}
$temp = count(file($dumpFile));
$handle = fopen($dumpFile, "a");
$toWrite = $temp . ";";
for ($i = 0; $i < $userCount; $i++) {
$toWrite .= $users[$i]["views"];
if ($i < $userCount - 1) {
$toWrite .= ";";
}
}
$toWrite .= "\n";
fwrite($handle, $toWrite);