Skip to content

Instantly share code, notes, and snippets.

@dansherman
Created December 4, 2015 21:07
Show Gist options
  • Save dansherman/ede85e48605792ec047a to your computer and use it in GitHub Desktop.
Save dansherman/ede85e48605792ec047a to your computer and use it in GitHub Desktop.
Rename and move shutterstock downloads.
#!/usr/bin/python
import lxml.html
import os
import re
import sys
r = r"(?<=shutterstock_)\d*(?=\.(jpg|eps))"
old_file = sys.argv[1]
picture_directory = '/Stock Images/'
n, file_ext = os.path.splitext(old_file)
if file_ext == ".eps":
picture_directory += "EPS/"
m = re.search(r,old_file)
pic = m.group()
S_URL = "http://shutterstock.com/pic-"
try:
t = lxml.html.parse(S_URL + pic)
new_name = t.find(".//title").text[:-15]
except:
new_name = pic
new_name += file_ext
new_file = os.path.join(picture_directory,new_name)
os.rename(old_file,new_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment