2018-02-13 22:31:30 +01:00
|
|
|
from datetime import timedelta
|
2018-02-05 21:44:37 +01:00
|
|
|
|
2018-09-17 21:18:24 +02:00
|
|
|
from raven import Client
|
|
|
|
|
|
|
|
import config
|
2018-02-05 21:44:37 +01:00
|
|
|
from models import *
|
2018-09-17 21:18:24 +02:00
|
|
|
from parser import kronehit, aas, orf, ara
|
|
|
|
|
|
|
|
if config.sentryDSN:
|
|
|
|
client = Client(config.sentryDSN)
|
2018-02-05 21:44:37 +01:00
|
|
|
|
|
|
|
headers = {
|
|
|
|
'User-Agent': 'Mozilla/5.0 (compatible; RadioStats/1.0;)',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def detect_show(artist, title):
|
2018-02-07 12:43:16 +01:00
|
|
|
return "Ö3" in artist or "LiveStream" in title or "Radio Tirol" in title \
|
|
|
|
or "mein radio" in title.lower() or "SCHOENSTEN OLDIES" in title \
|
2018-02-07 09:54:31 +01:00
|
|
|
or "RADIO STEIERMARK" in title or "Radio Burgenland" in title \
|
2018-02-07 12:46:24 +01:00
|
|
|
or "FM4 " in title or "Radio Salzburg" in title \
|
2018-02-08 15:40:00 +01:00
|
|
|
or "RADIO OÖ" == title or "Radio Wien" in title \
|
2018-02-07 12:46:24 +01:00
|
|
|
or (title == "" and artist == "")
|
2018-02-05 21:44:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_entry(time, artist, title):
|
|
|
|
print(time, artist, title)
|
2018-02-15 21:02:51 +01:00
|
|
|
if artist.isupper():
|
|
|
|
artist = artist.title()
|
|
|
|
if title.isupper():
|
|
|
|
title = title.title()
|
2018-02-18 10:21:20 +01:00
|
|
|
title = title.replace("+", " ")
|
2018-02-05 21:44:37 +01:00
|
|
|
try:
|
|
|
|
song_object = Song.get(artist=artist, title=title)
|
|
|
|
except DoesNotExist:
|
|
|
|
song_object = Song.create(artist=artist, title=title, show=detect_show(artist, title))
|
|
|
|
|
2018-02-06 15:26:01 +01:00
|
|
|
query = Play.select().where((Play.song == song_object) & (Play.channel == channel) &
|
2018-02-06 15:32:26 +01:00
|
|
|
(Play.time.between(time - timedelta(minutes=20), time + timedelta(minutes=20))))
|
2018-02-06 15:26:01 +01:00
|
|
|
if query.exists():
|
2018-02-05 21:44:37 +01:00
|
|
|
print("has already been added")
|
2018-02-06 15:26:01 +01:00
|
|
|
else:
|
2018-02-11 20:36:41 +01:00
|
|
|
try:
|
|
|
|
Play.create(song=song_object, channel=channel, time=time)
|
|
|
|
raise IntegrityError
|
|
|
|
except IntegrityError as error:
|
|
|
|
print(error)
|
2018-02-05 21:44:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
for channel in Channel.select():
|
2018-02-08 15:40:00 +01:00
|
|
|
if channel.has_data:
|
2018-02-13 22:31:30 +01:00
|
|
|
if channel.shortname == "kht":
|
|
|
|
pars = kronehit
|
|
|
|
elif channel.shortname == "886":
|
|
|
|
pars = aas
|
|
|
|
elif channel.shortname == "ara":
|
|
|
|
pars = ara
|
2018-02-25 14:58:30 +01:00
|
|
|
elif channel.shortname == "eng":
|
2018-06-08 21:34:45 +02:00
|
|
|
continue
|
2018-12-25 18:26:43 +01:00
|
|
|
elif channel.shortname == "all":
|
|
|
|
continue
|
2018-02-13 22:31:30 +01:00
|
|
|
else:
|
|
|
|
pars = orf
|
|
|
|
|
|
|
|
for time, artist, title in pars.get(channel):
|
2018-02-05 21:44:37 +01:00
|
|
|
add_entry(time, artist, title)
|