1
0
Fork 0
mirror of https://github.com/Findus23/RadioStats.git synced 2024-09-19 16:03:48 +02:00
RadioStats/fetch.py

52 lines
1.7 KiB
Python
Raw Normal View History

from datetime import timedelta
2018-02-05 21:44:37 +01:00
from models import *
from parser import kronehit, aas, orf, ara
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)
try:
song_object = Song.get(artist=artist, title=title)
except DoesNotExist:
song_object = Song.create(artist=artist, title=title, show=detect_show(artist, title))
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))))
if query.exists():
2018-02-05 21:44:37 +01:00
print("has already been added")
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:
if channel.shortname == "kht":
pars = kronehit
elif channel.shortname == "886":
pars = aas
elif channel.shortname == "ara":
pars = ara
else:
pars = orf
for time, artist, title in pars.get(channel):
2018-02-05 21:44:37 +01:00
add_entry(time, artist, title)