/usr/lib/python2.7/dist-packages/variety/BingDownloader.py is in variety 0.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# Copyright (c) 2012, Peter Levi <peterlevi@peterlevi.com>
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE
from datetime import datetime
import random
import urlparse
import logging
import re
from variety import Downloader
from variety.Util import Util
logger = logging.getLogger('variety')
random.seed()
class BingDownloader(Downloader.Downloader):
BING_JSON_URL = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=100&mkt=en-US" # n=100, but max 8 images are actually returned... Pity.
def __init__(self, parent):
super(BingDownloader, self).__init__(parent, "bing", "Bing", "https://www.bing.com/gallery/")
self.queue = []
def convert_to_filename(self, url):
return "Bing"
def download_one(self):
logger.info(lambda: "Downloading an image from Bing")
logger.info(lambda: "Queue size: %d" % len(self.queue))
if not self.queue:
self.fill_queue()
if not self.queue:
logger.info(lambda: "Bing queue empty after fill")
return None
origin_url, image_url, extra_metadata = self.queue.pop()
return self.save_locally(origin_url, image_url, extra_metadata=extra_metadata)
def fill_queue(self):
logger.info(lambda: "Filling Bing queue from " + self.location)
s = Util.fetch_json(BingDownloader.BING_JSON_URL)
for item in s['images']:
try:
image_url = 'https://www.bing.com' + item['url']
filename = item['url'].split('/')[-1]
name = filename[0:filename.find('_EN')]
src_url = 'https://www.bing.com/gallery/#images/%s' % name
try:
date = datetime.strptime(item['startdate'], '%Y%m%d').strftime('%Y-%m-%d')
except:
date = item['startdate']
extra_metadata = {
'sourceType': 'bing',
'sfwRating': 100,
'headline': 'Bing Photo of the Day, %s' % date,
'description': item['copyright'],
}
self.queue.append((src_url, image_url, extra_metadata))
except:
logger.exception(lambda: "Could not process an item in the Bing json result")
random.shuffle(self.queue)
logger.info(lambda: "Bing queue populated with %d URLs" % len(self.queue))
|