Skip to content

Instantly share code, notes, and snippets.

@breyten
Last active December 25, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breyten/1f7c75609dca06aa8cae to your computer and use it in GitHub Desktop.
Save breyten/1f7c75609dca06aa8cae to your computer and use it in GitHub Desktop.
Get ad spots based on broadcast
#!/usr/bin/env python
import os
import sys
import re
from pprint import pprint
import json
import MySQLdb
import requests
def get_spots(channel, db):
channelid = "RAD 1"
starttime = channel['startdatetime'].replace('T', ' ').replace('+01:00', '')
stoptime = channel['stopdatetime'].replace('T', ' ').replace('+01:00', '')
cursor = db.cursor()
r = cursor.execute(
"""SELECT * FROM `spots` WHERE channelid = %s AND broadcasttime >= %s AND broadcasttime <= %s""",
(channelid,
starttime,
stoptime,)
)
return cursor.fetchall()
if __name__ == '__main__':
db = MySQLdb.connect(user="spots", passwd="spots", db="sterspot")
channel = requests.get('http://radiobox2.omroep.nl/broadcast/rest/195969.json').json()
pprint(get_spots(channel, db))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment