Showing posts with label quick. Show all posts
Showing posts with label quick. Show all posts

Tuesday, 24 August 2010

It was time to write a python script to convert the 'copy to clipboard' data that filezilla generates, to something that can be used when posting links around the place. filezilla tends to output the URL with certain private FTP details, which is fine - but not great for spreading around. This thing looks at the link and rewrites it to the HTTP equivalent, nice for a couple of minutes work. As an added bonus the app copies the newly formatted link to my clipboard. The one thing that i did not manage to figure out was how to get the existing clipboard data into the textfield without having to ctrl+v.. something for a rainy day.



import sys
import re
from Tkinter import *


def urlReWrite(lameURL):

pat1 = r'.+(/public_html/)(.+)'
chip = re.match(pat1, lameURL)
goodURL = "http://digitalaphasia.com/" + chip.group(2)
return goodURL



class ClearApp:
def __init__(self, parent=0):
self.mainWindow = Frame(parent)
# Create the entry widget
self.entry = Entry(self.mainWindow, width=50)
# self.entry.insert(0,"Enter the URL here")
self.entry.pack(fill=X)

# now add the 2 buttons, use a grooved effect
fButtons = Frame(self.mainWindow, border=2, relief="groove")
bConvert = Button(fButtons, text="Convert",
width=8, height=1, command=self.convertURL)
bConvert.pack(side="left", padx=10, pady=1)

fButtons.pack(fill=X)
self.mainWindow.pack()

# set the title
self.mainWindow.master.title("URL converter")

def convertURL(self):
lameURL = self.entry.get()
self.entry.delete(0,END)
self.entry.insert(0, urlReWrite(lameURL))

app = ClearApp()
app.mainWindow.mainloop()