Finishes FlickrCollector

This commit is contained in:
Clément 2021-02-24 17:46:11 +01:00
parent 050788aabb
commit fa43eeb60d
1 changed files with 6 additions and 14 deletions

View File

@ -17,27 +17,18 @@ class FlickrCollector extends Collector
/**
* @return int
* @throws \Exception
*/
public function getRandomImage()
{
if (!$this->getConfig()->has('collector.flickr.key')) {
throw new \Exception('Flickr API key not found.');
}
$flickr_client = new PhpFlickr(
$this->getConfig()->get('collector.flickr.key'),
$this->getConfig()->get('collector.flickr.secret')
);
$word_to_search = $this->getConfig()->get('collector.keywords.keywords', $this->generateRandomWord());
$photos = $flickr_client->photos()->search($word_to_search);
var_dump($photos);
return $this->getRandomImages(1);
}
/**
* @param int $number
*
* @return int
* @throws \Exception
*/
public function getRandomImages(int $number)
{
@ -63,6 +54,7 @@ class FlickrCollector extends Collector
$img_url = sprintf('https://live.staticflickr.com/%s/%s_%s_b.jpg', $photo['server'], $photo['id'], $photo['secret']);
file_put_contents($this->getPoolDirectory() . '/' . basename(parse_url($img_url, PHP_URL_PATH)), file_get_contents($img_url));
}
var_dump($photos);
return $number;
}
}
}