Code:
import ImageGrab
import urllib, httplib, mimetypes,webbrowser,re,os
from winsound import PlaySound, SND_FILENAME, SND_ASYNC
def screenshot():
ImageGrab.grab().save('screenshot.jpg')
def post_multipart(host, port, selector, fields, files):
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTP(host, port)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
def encode_multipart_formdata(fields, files):
BOUNDARY = '---------------------------13049614110900'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s";filename="%s"' % (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or'application/octet-stream'
params = [('MAX_FILE_SIZE', '3145728'), ('refer','http://reg.imageshack.us/v_images.php')]
files = [('fileupload', 'screenshot.jpg', open('screenshot.jpg', 'rb').read())]
z = post_multipart('imageshack.us', 80, '/index.php', params, files)
for line in z.split('\n'):
if line.rstrip().lstrip().startswith("""<input type="text" onClick="track('direct');highlight(this)" style="width: 500px"""):
webbrowser.open(re.search('http://(.*?).imageshack.us/(.*?)/(.*?)/(.*?).jpg',line).group(),1,0)
os.remove('screenshot.jpg')
import threading,win32con,ctypes
from ctypes import wintypes
user32 = ctypes.windll.user32
byref = ctypes.byref
HOTKEYS = {
1 : (122,win32con.MOD_SHIFT),
}
for id, (vk, modifiers) in HOTKEYS.items ():
if not user32.RegisterHotKey (None, id, modifiers, vk):
PlaySound('C:\\Windows\\\Media\\Windows Hardware Fail.wav',SND_FILENAME|SND_ASYNC)
exit()
try:
msg = wintypes.MSG()
while user32.GetMessageA(byref(msg),None,0,0) != 0:
if msg.message == win32con.WM_HOTKEY:
try:
PlaySound('C:\\Windows\\\Media\\Windows Battery Low.wav',SND_FILENAME|SND_ASYNC)
screenshot()
except:
PlaySound('C:\\Windows\\\Media\\Windows Ding.wav',SND_FILENAME|SND_ASYNC)
user32.TranslateMessage(byref(msg))
user32.DispatchMessageA(byref(msg))
finally:
PlaySound('C:\\Windows\\\Media\\Windows Ding.wav',SND_FILENAME|SND_ASYNC)
user32.UnregisterHotKey (None, 1)