Skip to content

Instantly share code, notes, and snippets.

@metalrufflez
Created July 25, 2012 03:11
Show Gist options
  • Save metalrufflez/3174155 to your computer and use it in GitHub Desktop.
Save metalrufflez/3174155 to your computer and use it in GitHub Desktop.
Uploads a file to CloudApp and copies its link to the OSX Pasteboard
#!/usr/bin/python
'''
File: clly.py
Author: Caio "metalrufflez" Correa
Description: Upload a file to cloudapp and copies its link to the Pasteboard (OSX Only)
Dependencies: pycloudapp, poster, ordereddict
'''
import os
from sys import argv, exit
from cloudapp.cloud import Cloud
# Check if the you passed one and only one parameter
if len(argv) != 2:
print "USAGE: %s filename" % argv[0]
exit(1)
filename = argv[1]
username = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
# Check if the parameter exists (and it's a file)
if not os.path.isfile(filename):
print "File %s does not exists (or is a directory)" % filename
exit(1)
mycloud = Cloud()
# CloudApp login
try:
mycloud.auth(username, password)
except:
print "Error connecting to CloudApp."
print "Incorrect Username and Password."
exit(1)
# Uploads the file
try:
mycloud.upload_file(filename)
except:
print "Error uploading file to CloudApp."
print "Maybe you've exceeded your upload quota."
exit(1)
# Gets the last uploaded file (the one you just uploaded) and gets it's url
url = mycloud.list_items(page=1, per_page=1).pop()["url"]
# Put the url in the OSX Pasteboard
# (Resorted to os.popen cause the PyObjC wasn't working as I wished)
os.popen('pbcopy', 'w').write(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment