-
Notifications
You must be signed in to change notification settings - Fork 1
/
radio.py
executable file
·51 lines (40 loc) · 1.31 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
#!/usr/bin/env python2
import urllib2
import re
import httplib
import time
import os
from subprocess import call
test_mode = False
if test_mode:
os.chdir(os.path.realpath(__file__))
goz_test_file = "test.html"
html = open(goz_test_file).read()
else:
os.chdir(os.path.realpath(__file__))
goz_url = "http://www.radiobeograd.rs/index.php?option=com_content&task=view&id=29671&Itemid=335"
response = urllib2.urlopen(goz_url)
html = response.read()
# print html
linkovi = list(set([i for i in re.findall(
r'href="(?P<Str>download/Emisije/gozba/gozba\d+?\.mp3)"', html)]))
# print linkovi
# exit()
download_linkovi = []
for link in linkovi:
conn = httplib.HTTPConnection("www.radiobeograd.rs")
try:
conn.request("HEAD", '/'+link)
res = conn.getresponse()
# print res.status, res.reason
datum = time.strptime(res.getheader(
'last-modified'), "%a, %d %b %Y %H:%M:%S %Z")
fajl = "gozba-%s.mp3" % time.strftime('%y-%m-%d', datum)
download_linkovi.append(
" wget -c http://www.radiobeograd.rs/%s -O emisije/%s " % (link, fajl))
except urllib2.URLError, e:
print 1
print e.code
print e.read()
exec_str = " && ".join(download_linkovi)
os.system(exec_str)