It seems that there is a convenient thing called jpholidayp when cron is run only on weekdays.
For the usage and explanation, the following was easy to understand, so please refer to it. Emasaka / jpholidayp was great when I tried to judge holidays with cron
However, jpholidayp went to see the outside calendar at the time of execution, For various reasons, I can't go out unless I go through a proxy, so I played with the code a little.
Add about 4 lines between the 49th and 50th lines.
else:
#from here
proxy = {"http":"hoge-proxy:80"}
proxy_handler = urllib2.ProxyHandler(proxy)
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
#So far
res = urllib2.urlopen(self.URL)
dat = yaml.load(res)
cache.set({"holiday_jp": dat})
self.holiday_jp = dat
reference: [Note when running a crawler made with python's urllib2 in a proxy environment regularly with cron --moguranosenshi](http://moguranosenshi.hatenablog.com/entry/2013/10/16/%E3%83% 97% E3% 83% AD% E3% 82% AD% E3% 82% B7% E7% 92% B0% E5% A2% 83% E4% B8% 8B% E3% 81% A7python% E3% 81% AEurllib2% E3% 81% A7% E4% BD% 9C% E3% 81% A3% E3% 81% 9F% E3% 82% AF% E3% 83% AD% E3% 83% BC% E3% 83% A9% E3% 82% 92cron% E3% 81% A7)
Now in cron as it is
0 09 * * 1-5 /home/hoge/jpholidayp || /home/hoge/batch
If you do it, you can do it from Monday to Friday and on days other than holidays, so I'm happy.
(But of course there is no way to know if there are company, school, or organization-specific holidays. Don't want me to provide a holiday api for that organization)
Recommended Posts