~dhavlicek/awn-extras/dhavlicek

« back to all changes in this revision

Viewing changes to src/comic/getferdnand.py

  • Committer: Dave Havlicek
  • Date: 2009-01-30 17:54:50 UTC
  • Revision ID: dhavlicek@info.com-20090130175450-atwey8hvr872b0tg
dhavlicek bugfix branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License version 2 as
 
5
# published by the Free Software Foundation
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 
 
16
################################################################
 
17
# get_bornloser_strips.py -- fetch strips of last N days
 
18
 
 
19
################################################################
 
20
# BEGIN configuration
 
21
 
 
22
number_of_days = 1
 
23
 
 
24
path_prefix = '/tmp/' # where do you want to save the files?
 
25
 
 
26
# --END configuration
 
27
################################################################
 
28
 
 
29
import sys
 
30
import urllib
 
31
import re
 
32
 
 
33
from string import join
 
34
from datetime import datetime, timedelta
 
35
 
 
36
if len(sys.argv) > 1:
 
37
    number_of_days = int(sys.argv[1])
 
38
 
 
39
pattern  = re.compile('str_strip[0-9/]+\\.full\\.gif')
 
40
pattern2 = re.compile('str_strip[0-9/]+\\.full\\.jpg')
 
41
temp1 = 'http://comics.com/ferdnand/%s/'
 
42
temp2 = 'http://assets.comics.com/dyn/%s'
 
43
 
 
44
date = datetime.today()
 
45
one_day = timedelta(1)
 
46
 
 
47
filename = None
 
48
 
 
49
for i in range(number_of_days):
 
50
    url = temp1 % (date.strftime('%Y%m%d'))
 
51
    #print '? %s' % (url)
 
52
    fil = urllib.urlopen(url)
 
53
    for line in fil:
 
54
        match = pattern.search(line)
 
55
        if match != None:
 
56
            filename = match.group()
 
57
            break
 
58
        else:
 
59
            match2 = pattern2.search(line)
 
60
            if match2 != None:
 
61
                filename = match2.group()
 
62
                break
 
63
    fil.close()
 
64
 
 
65
    if filename != None:
 
66
        url = temp2 % (filename)
 
67
        #print '+ %s' % (url)
 
68
        fil = urllib.urlopen(url)
 
69
        diskfile = file(path_prefix + 'dilbert.gif', 'w')
 
70
        diskfile.write(fil.read())
 
71
        fil.close()
 
72
        diskfile.close()
 
73
 
 
74
    date = date - one_day
 
75
    filename = None