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

67 lines
2.2 KiB
Python
Raw Permalink Normal View History

from datetime import timedelta
2018-02-05 21:44:37 +01:00
2019-09-26 10:17:28 +02:00
import sentry_sdk
from peewee import DoesNotExist, IntegrityError
2018-09-17 21:18:24 +02:00
import config
2018-02-05 21:44:37 +01:00
from models import *
from parser import KroneHitFetcher, AchtundachzigsechsFetcher, ArabellaFetcher, OrfFetcher
2018-09-17 21:18:24 +02:00
if config.sentryDSN:
2019-09-26 10:17:28 +02:00
client = sentry_sdk.init(dsn=config.sentryDSN)
2018-02-05 21:44:37 +01:00
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)
2021-02-02 12:06:09 +01:00
if artist is None or title is None:
return
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("+", " ")
2021-02-14 18:27:10 +01:00
title = title.replace("NEU: ", "")
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))
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 = KroneHitFetcher()
elif channel.shortname == "886":
pars = AchtundachzigsechsFetcher()
elif channel.shortname == "ara":
pars = ArabellaFetcher()
2018-02-25 14:58:30 +01:00
elif channel.shortname == "eng":
continue
2018-12-25 18:26:43 +01:00
elif channel.shortname == "all":
continue
else:
pars = OrfFetcher()
for time, artist, title in pars.get(channel):
2018-02-05 21:44:37 +01:00
add_entry(time, artist, title)