Делаем короткие ссылки

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: cp1251 -*-
# импортируем библиотеки
from Tkinter import *
import urllib, urllib2
import re
import threading
import win32clipboard as w
import win32con
# <------------------------->
# создаём основное окно программы
root = Tk()
root.title("Shorten URL")
# <------------------------->
# функция уникализации текста
def Send_Parse():
textToWork = workURL.get(1.0,END)
shortURL.delete(1.0, END)
data = urllib.urlencode({"URL" : textToWork.encode("utf-8")})
textToWork = urllib2.Request("http://is.gd/create.php", data)
textToWork = urllib2.urlopen(textToWork).read()
textToWork = str(re.findall(r'\"\ value\=\".*?\"\ ', textToWork))[11:-4]
shortURL.insert(1.0, textToWork.strip())
return
def set_text():
setText(shortURL.get(1.0,END))
my = threading.Thread(target=Send_Parse)
# создаём элементы управления
topLabel = Label(root, text='Enter link here').grid(row=0, column=1,columnspan=2, sticky=W)
workURL = Text(root, height=7, width=35)
workURL.grid(row=1, column=1,columnspan=2)
shortURL = Text(root, height=1, width=35)
shortURL.grid(row=2, column=1, columnspan=2, sticky = W)
generateButton = Button(root, text='Short!', command=my.start).grid(row=3, column=1)
topLabel = Label(root, text="created by nikoTM").grid(row=3, column=2)
# <------------------------->
root.mainloop()