diff --git a/server/nightr/app.py b/server/nightr/app.py index a141134..6d65d1c 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -21,6 +21,7 @@ strategies = { "steam": (1.0, steam.probability), "australia": (1.0, miloStrats.australiaStrat), "camera": (1.0, miloStrats.camImgStrat), + "tv2news": (1.0, miloStrats.tv2newsStrat) } diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index a571d08..49875e6 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -1,9 +1,11 @@ from datetime import datetime +import requests import cv2 from pytz import timezone from ..util import Context, Prediction +#from server.nightr.util import Context, Prediction def camImgStrat(context : Context) -> Prediction: @@ -25,16 +27,37 @@ def camImgStrat(context : Context) -> Prediction: def australiaStrat(context : Context) -> Prediction: """ - Time in Australia + Using time in Australia """ australia = timezone('Australia/Melbourne') t = datetime.now().astimezone(australia) hour = t.hour p = Prediction() if hour > 22 or hour < 6: - p.probability = 1.0 - p.reasons.append('It\'s day-time in Australia') - else: p.probability = 0.0 p.reasons.append('It\'s night-time in Australia') + else: + p.probability = 1.0 + p.reasons.append('It\'s day-time in Australia') return p + +def tv2newsStrat(context : Context) -> Prediction: + r = requests.get('http://mpx.services.tv2.dk/api/latest') + data = r.json() + publish_dates = [(x['pubDate'])//1000 for x in data][:10] + delta_times = [] + for i in range(len(publish_dates)): + if i == 0 : continue + delta_times.append(publish_dates[i-1] - publish_dates[i]) + + avg_delta = 0 + for d in delta_times: + avg_delta += d + avg_timestamp = avg_delta // len(delta_times) // 60 + p = Prediction() + print('average time between articles on tv2:', avg_timestamp, 'minutes') + p.probability = 1.0 if avg_timestamp > 50 else 0.0 + p.reasons.append('There were ' + ('few' if avg_timestamp > 50 else 'many') + ' recent articles on TV2 News') + print(p.reasons[0]) + return p +