first release
[radio.git] / cgi-bin / icecast_last_songs.cgi
1 #!/usr/bin/python
2
3 import re
4 import sys
5
6 print "Content-type: application/json"
7 print ""
8
9 f = open("/var/log/icecast2/playlist.log", 'r')
10
11 print "["
12
13 first = True
14 for line in f:
15         p = re.compile("([^|]+)\|(.+)\|([0-9]+)\|(.+)")
16         m = p.match(line)
17         
18         if first:
19             first = False
20         else:
21                 print ','
22
23         sys.stdout.write("{ \"date\": \"" + m.group(1) + "\", \"listeners\": " + m.group(3) + ", \"song\": \"" + m.group(4) + "\" }")
24
25 print "]"