Created
December 4, 2015 21:07
-
-
Save dansherman/ede85e48605792ec047a to your computer and use it in GitHub Desktop.
Rename and move shutterstock downloads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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