Create a gist now

Instantly share code, notes, and snippets.

@viticci /CDN.py Secret
Created Mar 12, 2013

What would you like to do?
CDN
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Script: msia.py Version 1.0
# Author: Don Southard aka @binaryghost
# Date: December 5, 2012
# Modified for Pythonista
# Modified Date: January 19, 2013
# Resize function from Macdrifter
# http://www.macdrifter.com/2012/11/the-power-of-pythonista-12.html
import cloudfiles
import time
import os
import clipboard
import Image
from io import BytesIO
import sys
import photos
import workflow
import console
USERNAME = 'user'
API_KEY = 'key'
BUCKET = 'bucket'
def random():
return int(time.time())
def getImageName():
return 'image-%s.jpeg' % random()
def watermarkImage(image):
pass
def uploadToRackspace(image):
console.show_activity()
connection = cloudfiles.get_connection(username=USERNAME, api_key=API_KEY, serviceNet=True)
container = connection.get_container(BUCKET)
fileName = getImageName()
object = container.create_object(fileName)
bytes = BytesIO()
image.save(bytes, format='JPEG', quality=90)
object.send(bytes.getvalue())
workflow.set_output(object.public_uri())
console.hide_activity()
def main():
image = clipboard.get_image()
if not image:
image = photos.pick_image(show_albums=True)
uploadToRackspace(image)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment