archives
- January 2009 (1)
- December 2008 (1)
- November 2008 (2)
- October 2008 (4)
- September 2008 (2)
- August 2008 (4)
- July 2008 (10)
- June 2008 (5)
- May 2008 (5)
- April 2008 (10)
- March 2008 (13)
- February 2008 (3)
- January 2008 (7)
- December 2007 (7)
- November 2007 (9)
- October 2007 (10)
- September 2007 (1)
blogroll
30
Apr
I recently started a contest for a logo design (The link is not to my contest, just an example). Soon I had over 60 entries and I needed an easy way to present these logos to the client in a Power Point presentation. It takes two clicks to get to each image… no good. Thus the following script was created. It should serve as a good tutorial on how to use Python to do some basic web interactions.
#!/usr/bin/python import urllib import re # Change the variables "contest" and "path"
def retrieveImage( contest, path, name ):
url = "http://99designs.com/contests/" + contest + "/entries/" + name
urllib.urlretrieve( url, path + name )
if __name__ == '__main__':
contest = "6999" #The 99designs content number from which you want to extract images
path = "../tmp/" #The path where you want to store the downloaded images
url = urllib.urlopen( "http://99designs.com/contests/" + contest + "/feed" )
url_string = url.read()
p = re.compile( '\d*.large.\w{3,3}' )
iterator = p.finditer( url_string )
for match in iterator:
retrieveImage( contest, path , match.group() )
about
This blog provides programming, design, business and productivity content for tech entrepreneurs living in a 2.0 world.
Find out more about the author here.
Find out more about the author here.
categories
- Blogging (1)
- Business (38)
- Design (1)
- Django (1)
- FireFox 3 (1)
- General (4)
- GTD (1)
- Holiday (3)
- Life Hacks (23)
- Marketing (6)
- offbeat (3)
- Personal Development (9)
- Podcasting (1)
- Productivity (6)
- Programming (12)
- Python (1)
- Reviews (2)
- Sales (5)
- Social Networking (8)
- Symfony (1)
- Ubuntu (7)
- Video (3)
- Windows Vista (1)
- Windows XP (1)
- xv6800 (1)
members
most commented post
- » Managing Your Life With GTD, Online Tools and a File Cabinet - 19
- » How To Download Ustream.tv Videos - 12
- » Plurk Unleashed! - 12
- » Using The Web To Save on Holiday Gifts - 12
- » What Online Social Media Networks Do You Participate In? - 11
- » 19 Secrets From LA's Top SEO Firm - 10
- » The Story Behind iPhone.com - 10
- » Get Symfony Installed in 20 Minutes on Vista - 9
- » CSS Equivalent of Prototype? - 7
- » Thoughts are Things - 7
recent entries
- Afraid of Your ToDo List? 6 Steps to Courage
- 6 Phone Numbers for Your Mobile Speed Dial
- Using The Web To Save on Holiday Gifts
- GPS Nirvana with the Verizon xv6800 Running Windows Mobile 6.1
- Happy Holloween! Enjoy the Evil Pumpkin!
- Enterprise 2.0: Changing Models for Organization
- Digital Writing: Any Paper, Anywhere
- Emergency Economic Stabilization Act of 2008 - Talking Points
- How to Promote a Local Event
- BaseCamp Just Became Much More Usable
recent comments
- me: How does console access work if it all comes through the browser? Not seen a clear answer on this so far, mostly...
- Ian Utile: Great stuff! Appreciate you posting this…I will let others know
- Finomo-tech: The two finger scrolling thing works much better with IE7 than firefox. In firefox is much slower and I...
- elkhaircaddis: there is a cool xmas gift. it’s a digital frame but it’s different from the rest because...
- BeasMom: Awesome collection - thanks! Please add the gift of TIME to Group Gifting. Perfect for elderly relatives...
Wordpress theme by Wordpress Themes & made free by Internet Marketing Center
Copyright 2008, ThinkingSerious.com

May 2 2008
Overkill IMO. A less trivial example is going to get large and messy quickly. What about when the XML file in on an FTP, or requires authentication, needs some cookie, has to filter downloads by file size, wants to use a proxy, spawn multiple processes and so on? A more apt tool is curl or wget (I’m lazy so I used both). Also, when you keep it at the shell it’s more natural to pull in other shell commands when needed.
curl -s http://99designs.com/contests/6999/feed | grep -Po “src=\”.*(png|jpg)” | grep -o “http.*” | xargs wget -q
May 2 2008
Great example. Thanks for your contribution.
October 15 2008
Great tip using grep. I was going to use python, too.
My box doesn’t have the -P option
but I used egrep to similar effect. Also, the items I needed were in tags so I had to remove those with a sed command. The images were also retrieved from a database and didn’t have an extension so I did a one liner loop to rename those.
curl -s http://domain.tld/feed | egrep -o “.*” | egrep -o “(http.*)” | sed -e ’s/]*>//g’
for f in *; do mv ./”$f” “${f}.jpg”; done
October 15 2008
grep instead of python?…
…
October 15 2008
Ah… forgot to add the
| xargs wget -q
at the end of the curl,egrep line to do the actual downloading.