daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Dec 23rd, 2008 455 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import sys, os
  4.  
  5. #Define globals.
  6. tmp = "temp.data" #Temporary file filename.
  7. img = "" #Image filename.
  8. ext = "" #File extension.
  9.  
  10. #Define functions.
  11. def uploadsingle():
  12.         print("Uploading: " + img)
  13.         os.system("curl -H Expect: -F fileupload=\"@" + img + "\" -F xml=yes -# \"http://www.imageshack.us/index.php\" > " + tmp)
  14.  
  15.         file = open(tmp, "r")
  16.         content = file.read()
  17.  
  18.         #Get the image link.
  19.         start = content.find("<image_link>")
  20.         end = content.find("</image_link>")
  21.         link = content[start + 12 : end]
  22.  
  23.         #Get the thumbnail link.
  24.         start = content.find("<thumb_link>")
  25.         end = content.find("</thumb_link>")
  26.         forum_link = content[start + 12 : end]
  27.  
  28.         print("Image link:\t\t" + link)
  29.         print("Link for forums:\t[URL=" + link + "][IMG]" + forum_link + "[/IMG][/URL]")
  30.  
  31. def uploadall(extension):
  32.         print("Uploading: *." + extension)
  33.         outfile = open("links.txt", "a")
  34.         list = os.listdir("./")
  35.         for fname in list:
  36.                 if fname.endswith(ext):
  37.                         print("Uploading: " + fname)
  38.                         os.system("curl -H Expect: -F fileupload=\"@" + fname + "\" -F xml=yes -# \"http://www.imageshack.us/index.php\" > " + tmp)
  39.                         file = open(tmp, "r")
  40.                         content = file.read()
  41.                         #Get the image link.
  42.                         start = content.find("<image_link>")
  43.                         end = content.find("</image_link>")
  44.                         link = content[start + 12 : end]
  45.                         #Get the thumbnail link.
  46.                         start = content.find("<thumb_link>")
  47.                         end = content.find("</thumb_link>")
  48.                         forum_link = content[start + 12 : end]
  49.                         #Append link data to the outfile.
  50.                         outfile.write("File: " + fname + "\n")
  51.                         outfile.write("Image link:\t\t" + link + "\n")
  52.                         outfile.write("Link for forums:\t[URL=" + link + "][IMG]" + forum_link + "[/IMG][/URL]\n\n")
  53.                         os.system("rm " + tmp) #Remove temporary file.
  54.  
  55. #Process command line arguments and execute program.
  56. if sys.argv[1] == "all":
  57.         ext = sys.argv[2]
  58.         uploadall(ext)
  59. else:
  60.         img = sys.argv[1]
  61.         uploadsingle()
  62.  
  63. os.system("rm " + tmp) #Remove temporary file.
RAW Paste Data
Top