-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio.py
executable file
·64 lines (48 loc) · 1.92 KB
/
radio.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/python
import re
import argparse
from datetime import datetime, timedelta, time
import urllib2
from bs4 import BeautifulSoup
import urlutils
import sys
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='List shows for spesific radio channel',
epilog='For info contact [email protected]',
prog='Channel Program Listing')
parser.add_argument('-v','--version', action='version', version='%(prog)s 0.1')
parser.add_argument('-c','--channel', required=True,
help='The name of the channel to list programs for',
action='store')
parser.add_argument('-d','--days-from-today', type=int, help='Specify # days from today for listing of that day', default=0)
args = parser.parse_args()
urlutils.validateArgs(args)
print "Channel:", args.channel
urlbuild = urlutils.UrlBuilder(query='p_format=HTML')
plist = urlutils.ProgramListParams()
now = datetime.now()
now = now + timedelta(days=args.days_from_today)
day = now.day
month = now.month
year = now.year
print day, month, year
plist.setChannel(args.channel.upper())
plist.setFomDag(day)
plist.setFomMnd(month)
plist.setFomAr(year)
urlbuild.setQuery(plist)
response = urllib2.urlopen(urlbuild.__str__())
html = response.read()
soup = BeautifulSoup(html)
print soup.title.get_text()
starttimes = soup.find_all("td", "pubkl")
programs = soup.find_all("div", "pubprogtittel")
clock_now = datetime.now()
for starttime, program in zip(starttimes,programs):
timestamp = starttime.get_text()
hours = int(timestamp[:2])
minutes = int(timestamp[-3:])
hm = time(hours, minutes)
dpcomp = datetime.combine(now, hm)
if clock_now < dpcomp:
print starttime.get_text(), 'starts: ', program.get_text()