diff --git a/LocalStorage.php b/LocalStorage.php index 0eb009c..f4e42ee 100644 --- a/LocalStorage.php +++ b/LocalStorage.php @@ -18,6 +18,8 @@ protected function assign_data_value($type, $value) { } function setup_temporary_dir() { + $path="/tmp"; + $prefix="offlickr2."; // FIXME: Not atomic $tempname = tempnam($path,$prefix); if (!$tempname) { diff --git a/Offlickr2.php b/Offlickr2.php index 03fc41e..fff1937 100755 --- a/Offlickr2.php +++ b/Offlickr2.php @@ -396,8 +396,13 @@ private function get_photo_list() { if (count($photos['photo']) == 0) { break; } + if ($page > $photos['pages']) { + printf ("DEBUG: past the end of pages? $page > %s\n", $photos['pages']); + break; + } foreach ($photos['photo'] as $photo) { array_push($this->photo_list, $photo['id']); + printf ("DEBUG: %s %d\n", $photo['id'], $page); } $retrieved = count($this->photo_list); $this->dialog->info(2, "Total so far: " . $retrieved . " photo(s)"); diff --git a/oPhpFlickr.php b/oPhpFlickr.php index afbb74b..d2b073e 100644 --- a/oPhpFlickr.php +++ b/oPhpFlickr.php @@ -27,7 +27,7 @@ function authorize_console() { return $accessToken; } - function request ($command, $args = array()) { + function request ($command, $args = array(), $already_tried=0) { // NOTE: cache not implemented $args = array_merge( @@ -40,15 +40,26 @@ function request ($command, $args = array()) { $request = new OAuthRequest(Verb::POST, $args['url']); foreach ($args as $key => $value) { $request->addBodyParameter($key, $value); + print("*** request[" . $key . "]=" . $value . "\n"); } $this->oauth_service->signRequest($this->token, $request); $response_object = $request->send(); $response = $response_object->getBody(); - $this->parsed_response = json_decode($response, TRUE); + $this->parsed_response = json_decode($response, TRUE); if ($this->parsed_response['stat'] == 'fail') { - if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); - else { + if ($this->die_on_error) { + if ($already_tried > 3) { + die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); + } else { + print("warning: (retry {$already_tried}<=3) The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}\n"); + $sleep = 1 * 10**$already_tried; + print("Sleeping {$sleep} seconds\n"); + sleep($sleep); + $already_tried++; + $this->request($command, $args, $already_tried); + } + } else { $this->error_code = $this->parsed_response['code']; $this->error_msg = $this->parsed_response['message']; $this->parsed_response = false; @@ -62,4 +73,4 @@ function request ($command, $args = array()) { } -?> \ No newline at end of file +?>