-
Notifications
You must be signed in to change notification settings - Fork 1
/
noms
executable file
·49 lines (42 loc) · 1.71 KB
/
noms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding=utf-8 -*-
#
# Copyright © 2012 Jude Robinson (dotcode at gmail dot com | @dotcode)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from BeautifulSoup import BeautifulSoup
import urllib2
import re
import datetime
now = datetime.datetime.now()
# only run if between 9am and 2pm
if now.strftime('%H') >= '09' and now.strftime('%H') < '14':
page = urllib2.urlopen('http://eat.st/kings-cross/')
soup = BeautifulSoup(page)
# find the first date block (which is always the next eat st occurrence)
# The date is held inside a div.heading-blue
firstDateHeading = soup.find('div', 'heading-blue')
date = re.sub('^[^0-9]+', '', firstDateHeading.contents[0].string)
day = re.search('^[0-9]+', date)
# add leading zero to single digit dates
if len(day.group(0)) == 1:
day = '0' + day.group(0)
monthYear = re.search('[a-zA-Z]+ [0-9]+$', date)
firstDate = day + ' ' + monthYear.group(0)
# see if that first date matches today's date
if now.strftime('%d %b %Y') == firstDate:
for item in firstDateHeading.findNextSiblings('div'):
if item['class'] != 'altText':
break
print item.find('h3').find('a').string