Imageshack Screenshot Script


jdbye

Member
Joined
Dec 27, 2007
Messages
242
I based this script off the script in the screenshot tutorial, and another ImageShack script I found online.

It takes a screenshot, uploads it to ImageShack and copies the resulting URL to the clipboard :)
It does however require a few packages installed to NAND: xclip, curl, python-datetime
Easily installed by enabling wifi and running
Code:
sudo opkg update
sudo opkg install xclip curl python-datetime
They take less than 500kb in total so it shouldn't be a problem.

Accounts are supported using the regkey you received in the email when you first registered on ImageShack.
Best used in conjunction with the hotkeys tutorial: http://www.gp32x.de/board/index.php?/topic/54248-guide-hotkeys-ftw/

Script:

Code:
#!/usr/bin/python

import sys, os, datetime

#Define globals.
tmp = "temp.data" #Temporary file filename.
img = "" #Image filename.
ext = "" #File extension.
imageshackregcode = "" #Regcode from the registration email. Leave blank if you don't want to use an account.
screenshotdir = "/media/PANDORASD/screenshots/" #Dir to save the screenshot in

#Define functions.
def uploadsingle():
    filename = datetime.datetime.now().strftime("%y%m%d-%H%M%S") + ".png"
    img = screenshotdir + filename
	
    os.system("fbgrab \"" + img + "\"")
    os.system("notify-send \"Uploading " + img + "\" -t 3000")
    if imageshackregcode == "":
        os.system("curl -H Expect: -F fileupload=\"@" + img + "\" -F xml=yes -# \"http://www.imageshack.us/index.php\" > " + tmp)
    else:
        os.system("curl -H Expect: --cookie \"myimages=" + imageshackregcode + ";\" -F fileupload=\"@" + img + "\" -F xml=yes -# \"http://www.imageshack.us/index.php\" > " + tmp)
	

    file = open(tmp, "r")
    content = file.read()

    #Get the image link.
    start = content.find("<image_link>")
    end = content.find("</image_link>")
    link = content[start + 12 : end]

	
    os.system("echo -n " + link + " | xclip -selection clipboard")
    os.system("notify-send \"Image Link copied to clipboard\" -t 5000")

#Process command line arguments and execute program.

uploadsingle()

os.system("rm " + tmp) #Remove temporary file.

Copy the blob of text, save it somewhere as imgup.py (with UNIX line endings!), and use it like this (in a terminal):
Code:
python /path/to/imgup.py
Or, if you want to copy it to the NAND for easier usage:
Code:
sudo cp /path/to/imgup.py /usr/bin/imgup
sudo chmod ugo+x /usr/bin/imgup
It can then be run with:
Code:
imgup
...and easily added as a hotkey as well using the same command :)

I cooked this up quickly mainly for my own usage (and was annoyed by not being able to do anything without installing additional packages) but I thought other people might be interested in it.
It has zero error checking, so if anyone wants to add that or make other improvements to the script feel free to post your changes here. :)
 
Last edited by a moderator:

fusion_power

Advanced Member
Joined
Dec 25, 2005
Messages
13,134
Location
germany
Website
Visit site
That's interesting, at the PC I do use imageshack manualy. ^^""
But is there a way not to use "sudo opkg update"? It is not officialy recommended and can cause serious trouble onto the Pandora. ^^""
 

jdbye

Member
Joined
Dec 27, 2007
Messages
242
fusion_power said:
That's interesting, at the PC I do use imageshack manualy. ^^""
But is there a way not to use "sudo opkg update"? It is not officialy recommended and can cause serious trouble onto the Pandora. ^^""
Pretty sure that was opkg upgrade they were talking about. opkg update just updates the list of packages, upgrade updates all installed packages :)
opkg update has to be run at least once before you can use opkg install, so it has a list of packages it can use to look up the package you want to install.

There is a way though - download the ipk files manually from the Angstrom repository, and run:
Code:
sudo opkg install /path/to/package.ipk
Just use the search box there to find the package, and put it on a SD card or download it directly on the Pandora (you want the packages for armv7a) :)
 
Last edited by a moderator:
Joined
May 17, 2010
Messages
2,198
Location
:|
I've installed manually from the Angstrom repo myself, and... headaches. If you have the patience to resolve the dependencies by hand, it works :)
 

WizardStan

Mega GP Mania
Joined
May 24, 2008
Messages
16,733
fusion_power said:
That's interesting, at the PC I do use imageshack manualy. ^^""
But is there a way not to use "sudo opkg update"? It is not officialy recommended and can cause serious trouble onto the Pandora. ^^""
opkg update is only bad because it takes up about 30MB of precious NAND space.
 
Last edited by a moderator:

jdbye

Member
Joined
Dec 27, 2007
Messages
242
WizardStan said:
fusion_power said:
That's interesting, at the PC I do use imageshack manualy. ^^""
But is there a way not to use "sudo opkg update"? It is not officialy recommended and can cause serious trouble onto the Pandora. ^^""
opkg update is only bad because it takes up about 30MB of precious NAND space.
Ah, that explains why everyone downloads the ipk files instead. Will edit the first post :)
 
Last edited by a moderator:
Top