r11172 - in people: . evgeni evgeni/thumbnails-from-screenshots
Evgeni Golov
evgeni at alioth.debian.org
Thu Jul 29 15:09:10 UTC 2010
Author: evgeni
Date: 2010-07-29 15:09:08 +0000 (Thu, 29 Jul 2010)
New Revision: 11172
Added:
people/evgeni/
people/evgeni/thumbnails-from-screenshots/
people/evgeni/thumbnails-from-screenshots/fetch-thumbnails
Log:
add fetch-thumbnails python script
Added: people/evgeni/thumbnails-from-screenshots/fetch-thumbnails
===================================================================
--- people/evgeni/thumbnails-from-screenshots/fetch-thumbnails (rev 0)
+++ people/evgeni/thumbnails-from-screenshots/fetch-thumbnails 2010-07-29 15:09:08 UTC (rev 11172)
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+
+# fetch-thumbnails
+#
+# Copyright 2010 Evgeni Golov <evgeni at debian.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from debian import debtags
+import json
+import urllib2
+from PIL import Image
+from os import path, mkdir
+
+__BASE_DIR = 'build'
+__ORIG_DIR = '%s/orig' % __BASE_DIR
+__THUMB_DIR = '%s/thumbs' % __BASE_DIR
+
+__JSON_URL = 'http://screenshots.debian.net/json/screenshots'
+__DEBTAGS_FILE = '/var/lib/debtags/debtags-fetch-apt.tag'
+__FACET = 'game'
+
+if not path.exists(__BASE_DIR):
+ mkdir(__BASE_DIR)
+if not path.exists(__ORIG_DIR):
+ mkdir(__ORIG_DIR)
+if not path.exists(__THUMB_DIR):
+ mkdir(__THUMB_DIR)
+
+screenshots = json.load(urllib2.urlopen(__JSON_URL))
+screenshots = screenshots['screenshots']
+
+db = debtags.DB()
+db.read(open(__DEBTAGS_FILE, "r"))
+games = db.filter_tags(lambda t: t.startswith(__FACET))
+
+work = []
+
+for g in games.iter_packages():
+ p = {}
+ if 'role::program' in db.tags_of_package(g):
+ p['name'] = g
+ p['screenshot'] = None
+ for s in screenshots:
+ if s['name'] == g:
+ p['screenshot'] = s['large_image_url']
+ work.append(p)
+ break
+
+for p in work:
+ if p['screenshot']:
+ print "Fetching screenshot for %(name)s from %(screenshot)s" % p
+ f = file("%s/%s.png" % (__ORIG_DIR, p['name']), "wb")
+ f.write(urllib2.urlopen(p['screenshot']).read())
+ f.close()
+ img = Image.open("%s/%s.png" % (__ORIG_DIR, p['name']))
+ if img.size[0] > img.size[1]:
+ scale = img.size[0]/320.0
+ new_size = (320, int(round(img.size[1]/scale)))
+ else:
+ scale = img.size[1]/240.0
+ new_size = (int(round(img.size[0]/scale)), 240)
+ i = img.resize(new_size)
+ i.save("%s/%s.png" % (__THUMB_DIR, p['name']))
+ else:
+ print "WARNING: %(name)s has no screenshot!" % p
Property changes on: people/evgeni/thumbnails-from-screenshots/fetch-thumbnails
___________________________________________________________________
Added: svn:executable
+ *
More information about the Pkg-games-commits
mailing list