on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?
such as
http://comics.com/peanuts/
Update: i know how to download the image as a file. the hard part is how to email it from my local Windows machine.
A quick look on google reveals two command-line programs that you should be able to lash together in a batch file or using the scripting language of your choice.
http://www.gnu.org/software/wget/ - to do the download
http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm - to send the email
You can use the Windows Task Scheduler in control panel to make it run daily.
If you are using Python there are surely going to be convenient libraries to do the downloading/emailing parts - browse the official Python site.
This depends how precise you want to be. Downloading the entire web page wouldn't be too challenging - using wget, as Earwicker mentions above.
If you want the actual image file of the comic downloaded, you would need a bit more in your arsenal. In Python - because that's what I know best - I would imagine you'd need to use urllib to access the page, and then a regular expression to identify the correct part of the page. Therefore you will need to know the exact layout of the page and the absolute URL of the image.
For XKCD, for example, the following works:
#!/usr/bin/env python
import re, urllib
root_url = 'http://xkcd.com/'
img_url = r'http://imgs.xkcd.com/comics/'
dl_dir = '/path/to/download/directory/'
# Open the page URL and identify comic image URL
page = urllib.urlopen(root_url).read()
comic = re.match(r'%s[\w]+?\.(png|jpg)' % img_url, page)
# Generate the filename
fname = re.sub(img_url, '', comic)
# Download the image to the specified download directory
try:
image = urllib.urlretrieve(comic, '%s%s' % (dl_dir, fname))
except ContentTooShortError:
print 'Download interrupted.'
else:
print 'Download successful.'
You can then email it however you feel comfortable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With