Calazan.com
Share the Knowledge-
Python script for auto-renaming your image files
Posted on January 19th, 2012 No comments
Print
I like to rename my pictures a certain way as soon as I import them to my computer. I usually follow this format: description_datetaken_3digitnumbering.jpgI was using Metamorphose to do this for a while. But one time I wanted to rename my pictures while I was in New Zealand and realized I didn’t have the application installed on my netbook. I didn’t want to pay the $5 for the Internet access so I decided to just hack together a simple Python script to do it. I haven’t gone back to Metamorphose ever since. I found my script easier to use as I had it customized for my needs.
I’ve tweaked it quite a bit to make it even more user friendly. Here’s the script if you’re interested. Note that I’m not sure whether the EXIF tag attributes are the same for your camera, so you might need to modify it a little to work for you.
import os import sys import shutil import datetime from PIL import Image from PIL.ExifTags import TAGS # Check first if the given path exists before continuing to the next step. while True: folderpath = raw_input('Folder path: ') print "\nChecking if folder path exists...\n" if os.path.exists(folderpath): print "Ok!\n" break; else: print "%s does not exist. Please enter a valid path.\n" % folderpath filename_pattern = raw_input('Filename pattern: ') def get_exif_data(filename): """Get embedded EXIF data from image file. Source: http://www.endlesslycurious.com/2011/05/11/extracting-image- exif-data-with-python/ """ ret = {} try: img = Image.open(filename) if hasattr( img, '_getexif' ): exifinfo = img._getexif() if exifinfo != None: for tag, value in exifinfo.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value except IOError: print 'IOERROR ' + filename return ret def get_date_taken(filename): datestring = get_exif_data(current_file)['DateTimeOriginal'] return datetime.datetime.strptime(datestring, '%Y:%m:%d %H:%M:%S') def get_filenames(): os.chdir(folderpath) return os.listdir(os.getcwd()) def get_numbering_format(digits, num): if digits == 1: numberfmt = '00%s' % num elif digits == 2: numberfmt = '0%s' % num else: numberfmt = '%s' % num return numberfmt def date_to_string(dateobj, format): return datetime.datetime.strftime(dateobj, format) def multi_replace(text, dictobj): """Replace characters in the text based on the given dictionary.""" for k, v in dictobj.iteritems(): text = text.replace(k, v) return text if __name__ == '__main__': filenames = get_filenames() for i in xrange(len(filenames)): num = i + 1 digits = len(str(num)) current_file = filenames[i] # Only rename files, ignore directories. if not os.path.isdir(current_file): # Key, value pairs of what to replace. dictobj = { '<num>': get_numbering_format(digits, num), '<datetaken>': date_to_string(get_date_taken(current_file), '%Y%m%d') } new_filename = multi_replace(filename_pattern, dictobj) shutil.move(current_file, new_filename)Sample Usage
Notes
- PIL (Python Imaging Library) is required to retrieve the EXIF data.
- I decided not to traverse subdirectories as that could be pretty dangerous if the wrong path is accidentally entered.
- It’s set to pad the numbering to 3 digits.
- It will rename any file that is not a directory (maybe add a check later for file type).
-
RTW Trip Day 1
Posted on January 15th, 2012 No comments
Print
I am now officially homeless!
Made it in one piece to Playa del Carmen, Mexico today. I’m staying in a hostel near 5th Avenue. Just finished taking a walk, nice breeze outside. Can’t wait to just chill out on the beach tomorrow.
From here I’m planning on taking a bus to Belize, then to Guatemala. Thinking of staying in Mexico and Belize only for a few days.
My current itinerary basically stops in Guatemala as I’m planning on staying there for a while and take some Spanish lessons. Not sure yet exactly how long I’ll be staying there and which country to visit after that. I’ll probably just keep going south and hopefully after Guatemala I’ll know enough Spanish so I can practice it as I visit other Latin American countries.
Just gonna take things slowly the next few days, looking to get a lot of reading done.
-
Choosing a RTW Travel Insurance
Posted on January 11th, 2012 2 comments
Print
I’ve been researching on and off which travel insurance to get for a few months now. I finally purchased one last week as my upcoming trip is getting pretty close.
I decided to go with World Nomads and purchased a 6-month policy. I’m planning to be away for at least a year but I only went with the 6-month policy since it came out to be the best deal at $386.24 ($64.37/month) for the “Explorer” option (compared to a 12-month policy at $1,211.78 ($100.98/month)).
I asked @WorldNomads why a 6-month policy is much cheaper than a 12-month one on Twitter (love it when a company makes it easy for their customers to reach out to them) and their GM, Chris, responded that in theory, the longer you travel the higher the risk of something happening to you. World Nomads allows you to extend your policy while on the road, which is great if you’re like me and not sure how long you’ll be away. Their target audience really seems to be, well, nomads.
I really like how simple and easy it is to purchase insurance from them. Simply enter your country of residence, the start date, and policy duration and they’ll show you the price and a nice summary of what’s covered. No questions about how old you are (note that they can only cover you if you’re under 67), when you are coming back, which countries you’re visiting, estimated cost of the trip, etc. You’re covered worldwide and domestic (if at least 100 miles away from home). The policy ends when you return home.
They have two plans: “Standard” (the cheaper option) and “Explorer.” I went with the “Explorer” plan as there are some activities I’m planning on doing that are not covered by the “Standard” plan. The “Explorer” plan also has car rental collision coverage and has a higher maximum coverage for things such as emergency evacuation and trip cancellation (click here for a sample comparison).
Submitting a claim can also be done online. I’ve read good things about how they handled claims from forum posts while doing my research. This, in addition to being able to renew/extend the policy on the road and the simplicity of the process, are really what convinced me to go with them.
Note: The stuff I mentioned above are for US residents.
Some suggestions to World Nomads (geek warning, you might want to skip this):
1. Automatically redirect your signup and login pages to HTTPS (for encrypted communication). I almost didn’t signup with them when I saw these pages with no encryption. But I manually added the “s” in the URL and it worked. Any web page that displays and allows input of sensitive/personal information should be encrypted. Automatic redirect is very easy to do.
2. Encrypt all elements of the page (SSL at the credit card submission page shows “mixed content” warning). I didn’t check which elements of the page is non-SSL but this could be a security issue (plus it’s annoying to see it): https://www.golemtechnologies.com/articles/mixed-content
3. Don’t store your users’ passwords in plain text. I just found out about this today as I’ve forgotten my password. They sent me an email with the actual password I set. This is not good! It usually means the passwords are stored in the database in their original form (either that or a reversible encryption is used). If someone hacks their user database, the hacker gets all the passwords with no extra work for them (or a disgruntled employee steals them, someone will have full access to that database). Chances are a good amount of the users probably use that same password for other things as well, such as their email account, banking, etc. Passwords should be stored using a one-way hashing algorithm such as MD5 or SHA-1 with salt. When a user forgets the password, a new password should either be randomly generated (and require the user to change it on first use) or send a user a link that expires that allows them to set a new password. I know it makes it inconvenient for the users as well, but it’s for their own security.
4. Log in using either the username or email address. Minor thing, but would be nice if you could login with either or. Sometimes I sign up to something and I forget what username I used.
I mentioned #1 to Chris from World Nomads and he said they’re currently working on improving a lot of things which should hopefully address all the issues I encountered above: https://twitter.com/#!/WorldNomads/status/153950913206296576
Other companies I checked out:
Travel Guard - I’ve read good things about Travel Guard as well. World Nomads actually uses them as an underwriter. I went to their website to try and get a quote but they asked a bunch of questions there that I had no answer to yet (such as trip deposit date, final payment date, and the country where I’ll be spending the most time), so I just put some guesses/estimates. They showed me 3 different plans, the cheapest/most basic (called “My Travel Guard”) was only $105.81 for 6 months, but missing a lot of things that World Nomads cover. The second cheapest (“Gold”) is $633 and the most expensive (“Platinum”) is $825. Much more expensive than World Nomads’. ”Gold” and “Platinum” plans offer pre-existing condition waiver, however, which World Nomads doesn’t offer.
Columbus Direct – Got a quote for a “Backpacker travel” insurance. The coverage that’s closest to World Nomads’ is their “Gold Single Trip” plan for $633, and World Nomads has the better coverage. Medical expense coverage, for example, is only $25,000 for that plan, compared to $100,000 with the World Nomads Explorer plan.
There are probably better deals out there, but I didn’t want to spend any more time researching as I find World Nomads already meets most of my needs at a very reasonable price. Travel Guard and Columbus Direct give you more options, though, so if you need a more customized coverage definitely check them out.
HTH – Just found out about this from Caroline (see comment below). Put my info and they quoted me $266.22 for 6 months (New Jersey, age 27) for their TravelGap Excursion plan. This actually looks very good as they cover pre-existing conditions and the medical limit is $1,000,000 with no deductible. Something for me to consider once the policy I bought from World Nomads ends (thanks Caroline!).




Recent Comments