Skip to content

Instantly share code, notes, and snippets.

@batok
Created July 12, 2009 02:18
Show Gist options
  • Save batok/145488 to your computer and use it in GitHub Desktop.
Save batok/145488 to your computer and use it in GitHub Desktop.
import urllib
import json
import wx
login = "your_bitly_login_name"
apikey = "your api key"
l_url= "http://www.google.com" # just a default url, can be anyone
app = wx.PySimpleApp()
app.MainLoop()
l_url = wx.GetTextFromUser( message = "Please Type URL", caption ="bit.ly shorten", default_value = l_url)
value = urllib.urlopen("http://api.bit.ly/shorten?version=2.0.1&longUrl=%s&login=%s&apiKey=%s" % ( l_url, login, apikey)).read()
d = json.loads(value)
bitly_url = str( d.get("results").get(l_url).get("shortUrl"))
txt = wx.TextDataObject( bitly_url )
if wx.TheClipboard.Open():
wx.TheClipboard.SetData( txt )
wx.TheClipboard.Close()
wx.MessageBox("%s is in clipboard" % bitly_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment