def save_sr_image(sr, data, suffix='.png'): try: return upload_media(data, file_type=suffix) except Exception as e: raise BadImage(e)
def save_sr_image(sr, data, suffix = '.png'): try: return upload_media(data, file_type = suffix) except Exception as e: raise BadImage(e)
from r2.lib.media import upload_media from r2.models.subreddit import Subreddit from r2.models.wiki import WikiPage, ImagesByWikiPage all_subreddits = Subreddit._query(sort=desc("_date")) for sr in fetch_things2(all_subreddits): images = sr.images.copy() images.pop("/empties/", None) if not images: continue print 'Processing /r/%s (id36: %s)' % (sr.name, sr._id36) # upgrade old-style image ids to urls for name, image_url in images.items(): if not isinstance(image_url, int): continue print " upgrading image %r" % image_url url = "http://%s/%s_%d.png" % (g.s3_old_thumb_bucket, sr._fullname, image_url) image_data = urllib2.urlopen(url).read() new_url = upload_media(image_data, file_type=".png") images[name] = new_url # use a timestamp of zero to make sure that we don't overwrite any changes # from live dual-writes. rowkey = WikiPage.id_for(sr, "config/stylesheet") ImagesByWikiPage._cf.insert(rowkey, images, timestamp=0)
from r2.models.subreddit import Subreddit from r2.models.wiki import WikiPage, ImagesByWikiPage all_subreddits = Subreddit._query(sort=desc("_date")) for sr in fetch_things2(all_subreddits): images = sr.images.copy() images.pop("/empties/", None) if not images: continue print 'Processing /r/%s (id36: %s)' % (sr.name, sr._id36) # upgrade old-style image ids to urls for name, image_url in images.items(): if not isinstance(image_url, int): continue print " upgrading image %r" % image_url url = "http://%s/%s_%d.png" % (g.s3_old_thumb_bucket, sr._fullname, image_url) image_data = urllib2.urlopen(url).read() new_url = upload_media(image_data, file_type=".png") images[name] = new_url # use a timestamp of zero to make sure that we don't overwrite any changes # from live dual-writes. rowkey = WikiPage.id_for(sr, "config/stylesheet") ImagesByWikiPage._cf.insert(rowkey, images, timestamp=0)
def save_sr_image(sr, data, suffix = '.png'): try: return upload_media(data, file_type = suffix) except Exception as e: g.log.exception("Error in upload media") raise BadImage(e)