Results 1 to 10 of 10

Thread: [Python] Screenshot taker and uploader

  1. #1
    Join Date
    Jan 2007
    Posts
    131
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default [Python] Screenshot taker and uploader

    I got bored of taking screen shots using the keyboard, then pasting it in paint and uploading it myself. So I made this script to do it for me.
    It runs in the background, and will take a screenshot when you press shift+F11, save it, play a notification sound (One of vistas default ones) then upload it to imageshack, and then it even opens a browser window with the direct link to the image.

    Save it as a .pyw file - so when you run it it will not open a console window.

    It requires python 2.6, PIL and the Win32 extensions.

    Downloads:
    Win32 extensions: http://sourceforge.net/projects/pywin32/
    PIL: http://www.pythonware.com/library/
    Python: http://www.python.org

    Code:
    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)

  2. #2
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    There are easyer ways of doing this for example for taking screenshots of the mm for map walking would be like this but mine takes screen shots as u play it
    ctrl + alt + R
    to run

    SCAR Code:
    Procedure SaveMM;
    var
      MMBMP, A : integer;
      SFile : String;
    Begin
      Repeat
        Inc(A);
        If Not FileExists(ScriptPath + 'MM'+IntToStr(A)+'.bmp') Then Break;
      Until(Not FileExists(ScriptPath + 'MM'+IntToStr(A)+'.bmp'));
      SFile := ScriptPath + 'MM'+IntToStr(A)+'.bmp';
      CopyClientToBitmap(MMBMP,519,0,764,167); // coords of MM could be changed
                                               // e.g. inv for items in rs
      SaveBitmap(MMBMP, SFile);
      Writeln('Saved to '+ScriptPath+'MM'+IntToStr(A)+'.bmp');
    End;
    any Way still looks good

    Edit : This Doesnt upload could be made to...

  3. #3
    Join Date
    Jan 2007
    Posts
    131
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This does not run in the background (Like a windows service), or respond to hotkeys. If you are trying to screenshot a your desktop, you don't want scar in the way! The advantage is the ability to select an area to save, and that's pretty cool. Also, it doesn't open a browser window and load the uploaded image URL.

  4. #4
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by bobng View Post
    This does not run in the background (Like a windows service), or respond to hotkeys. If you are trying to screenshot a your desktop, you don't want scar in the way! The advantage is the ability to select an area to save, and that's pretty cool. Also, it doesn't open a browser window and load the uploaded image URL.

    In SCAR there is function that Minimizes SCAR. It's like GetSelf.Hide; or some thing like that? Then you can tel SCAR to hold down the hotkeys to bring it back up.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  5. #5
    Join Date
    Jan 2007
    Posts
    131
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by noidea View Post
    In SCAR there is function that Minimizes SCAR. It's like GetSelf.Hide; or some thing like that? Then you can tel SCAR to hold down the hotkeys to bring it back up.
    It still does not run in the background, like a service.

    I could also make the upload threaded, so you can take multiple snapshots then make a thread for each one which uploads it.
    Can scar do that?

  6. #6
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by bobng View Post
    It still does not run in the background, like a service.
    It could. Just use that GetSelf.Hide; and have like a
    SCAR Code:
    repeat
      wait(150)
    until isfkey(12);//or w/e this proc is
    TakeScreenyCrap;

    Edit: Here, like this...
    SCAR Code:
    Procedure SaveMM;
    var
      MMBMP, A : integer;
      SFile : String;
    Begin
      getself.hide;//or w/e
      repeat  
        repeat
          wait(150)
        until isfkey(12);//or w/e  
        Inc(A);
        If Not FileExists(ScriptPath + 'MM'+IntToStr(A)+'.bmp') Then Break;
        Until(Not FileExists(ScriptPath + 'MM'+IntToStr(A)+'.bmp'));
        SFile := ScriptPath + 'MM'+IntToStr(A)+'.bmp';
        CopyClientToBitmap(MMBMP,519,0,764,167); // coords of MM could be changed
                                               // e.g. inv for items in rs
        SaveBitmap(MMBMP, SFile);
        Writeln('Saved to '+ScriptPath+'MM'+IntToStr(A)+'.bmp');
      until false
    End;

    I didn't compile this or anything so I doubt it would work...
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  7. #7
    Join Date
    Jan 2007
    Posts
    131
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by noidea View Post
    It could. Just use that GetSelf.Hide; and have like a
    ScarScript:By Drunkenoldma
    repeat wait(150) until isfkey(12);//or w/e this proc is TakeScreenyCrap;
    It still doesn't run in the background, like service (Hint: Without a window)

  8. #8
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by bobng View Post
    It still doesn't run in the background, like service (Hint: Without a window)
    Yes it will. GetSelf.hide; puts SCAR into the task bar thing next to the clock.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  9. #9
    Join Date
    Jan 2007
    Posts
    131
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Fair enough. Make it upload and respond to a hotkey then I will be impressed.

  10. #10
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Thats what the script I/that other guy posted does. I havent tried to compile it though so there are errors.

    Eddit: nvm, it doesn't upload it. It just saves it and and responds to the hotkey.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Release of File Uploader
    By Harry in forum News and General
    Replies: 39
    Last Post: 04-01-2009, 11:48 PM
  2. Screenshot
    By Floor66 in forum OSR Help
    Replies: 3
    Last Post: 11-03-2008, 07:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •