diff --git a/.gitignore b/.gitignore index 0bc8854..b264155 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ sikweb/settings.py *.sqlite3 uwsgi.ini uwsgi.log -infoscreen/static/js/hsl.json members/logs/* .idea/ logs/ diff --git a/infoscreen/hsl_fetcher.py b/infoscreen/hsl_fetcher.py deleted file mode 100644 index 6a3835c..0000000 --- a/infoscreen/hsl_fetcher.py +++ /dev/null @@ -1,70 +0,0 @@ -"""File containing Infoscreen HSL data fetcher classes.""" - -import requests -import json -import logging -import os -import pytz - -from datetime import timedelta, datetime -from django.utils import timezone, dateparse -from django.utils.dateformat import format - -from django.conf import settings - - -with open(os.path.join(settings.BASE_DIR, 'infoscreen', 'hsl_stops.graphql')) as stops_file: - STOPS_QUERY = stops_file.read() - -with open(os.path.join(settings.BASE_DIR, 'infoscreen', 'hsl_stops_variables.json')) as vars_file: - STOPS_VARS = json.loads(vars_file.read()) - -API_URL = 'https://api.digitransit.fi/routing/v1/routers/hsl/index/graphql' -API_HEADERS = {'Content-Type': 'application/json'} - - -def fetch(): - """Fetch data from HSL API.""" - - query_vars = STOPS_VARS.copy() - query_vars['startTime_6'] = format(timezone.now(), 'U') - - post_data = json.dumps({ - 'operationName': 'NearestRoutesContainer', - 'query': STOPS_QUERY, - 'variables': query_vars, - }) - - resp = requests.post(API_URL, data=post_data, headers=API_HEADERS) - - data = resp.json() - - items = data['data']['viewer']['_nearest']['edges'] - places = map(lambda item: item['node']['place'], items) - - schedule = [] - for place in places: - route = place['pattern']['route']['shortName'] - stop_times = place['_stoptimes'] - for stop_time in stop_times: - timestamp = time_utc = stop_time['serviceDay'] + stop_time['realtimeArrival'] - headsign = stop_time['stopHeadsign'] - stop_name = stop_time['stop']['name'] - time_diff = (timestamp - timezone.now().timestamp()) / 60 # minutes - - if time_diff < settings.HSL_DEPARTURE_THRESHOLD: - continue - elif time_diff < settings.HSL_HURRY_THRESHOLD: - time = '{} min'.format(int(time_diff)) - else: - time = pytz.utc.localize(datetime.fromtimestamp(timestamp)).strftime('%H:%M') - - schedule.append({ - 'route': route, - 'headsign': headsign, - 'timestamp': time, - 'stop': stop_name, - 'utc': time_utc, - }) - - return schedule diff --git a/infoscreen/hsl_stops.graphql b/infoscreen/hsl_stops.graphql deleted file mode 100644 index 6111303..0000000 --- a/infoscreen/hsl_stops.graphql +++ /dev/null @@ -1,71 +0,0 @@ -query NearestRoutesContainer($lat_0: Float!, $lon_1: Float!, $maxDistance_2: Int!, $maxResults_3: Int!, $timeRange_7: Int!, $numberOfDepartures_8: Int!, $filterByModes_4: [Mode]!, $filterByPlaceTypes_5: [FilterPlaceType]!, $startTime_6: Long!) { - viewer { - ...F5 - } -} - -fragment F0 on DepartureRow { - _stoptimes4caEfh: stoptimes(startTime: $startTime_6, timeRange: $timeRange_7, numberOfDepartures: $numberOfDepartures_8) { - pickupType - serviceDay - realtimeDeparture - } - id -} - -fragment F1 on DepartureRow { - pattern { - route { - shortName - } - } - _stoptimes: stoptimes(startTime: $startTime_6, timeRange: $timeRange_7, numberOfDepartures: $numberOfDepartures_8) { - realtimeArrival - serviceDay - stopHeadsign - stop { - name - } - } -} - -fragment F2 on BikeRentalStation { - id -} - -fragment F3 on placeAtDistance { - distance - place { - id - __typename - ...F1 - ...F2 - } - id -} - -fragment F4 on placeAtDistanceConnection { - edges { - node { - distance - place { - id - __typename - ...F0 - } - id - ...F3 - } - cursor - } - pageInfo { - hasNextPage - hasPreviousPage - } -} - -fragment F5 on QueryType { - _nearest: nearest(lat: $lat_0, lon: $lon_1, maxDistance: $maxDistance_2, maxResults: $maxResults_3, first: $maxResults_3, filterByModes: $filterByModes_4, filterByPlaceTypes: $filterByPlaceTypes_5) { - ...F4 - } -} \ No newline at end of file diff --git a/infoscreen/hsl_stops_variables.json b/infoscreen/hsl_stops_variables.json deleted file mode 100644 index bcc8e18..0000000 --- a/infoscreen/hsl_stops_variables.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "lat_0": 60.190480099999995, - "lon_1": 24.8275665, - "maxDistance_2": 1000, - "maxResults_3": 50, - "numberOfDepartures_8": 2, - "timeRange_7": 7200, - "filterByModes_4": ["BUS"], - "filterByPlaceTypes_5": ["DEPARTURE_ROW"] -} diff --git a/infoscreen/management/commands/hsl.py b/infoscreen/management/commands/hsl.py deleted file mode 100644 index 5fb2061..0000000 --- a/infoscreen/management/commands/hsl.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.core.management.base import BaseCommand -from infoscreen.hsl_fetcher import HSLFetcher - - -class Command(BaseCommand): - help = 'Loads HSL timetables and save to json file.' - - def handle(self, *args, **options): - fetcher = HSLFetcher() - fetcher.fetch() diff --git a/infoscreen/migrations/0006_delete_hsldatamodel.py b/infoscreen/migrations/0006_delete_hsldatamodel.py index c660813..9214e52 100644 --- a/infoscreen/migrations/0006_delete_hsldatamodel.py +++ b/infoscreen/migrations/0006_delete_hsldatamodel.py @@ -15,4 +15,11 @@ class Migration(migrations.Migration): migrations.DeleteModel( name='HSLDataModel', ), + migrations.RemoveField( + model_name='hslinfoitem', + name='infoitem_ptr', + ), + migrations.DeleteModel( + name='HslInfoItem', + ), ] diff --git a/infoscreen/models.py b/infoscreen/models.py index 18d2b0a..e1479f8 100644 --- a/infoscreen/models.py +++ b/infoscreen/models.py @@ -254,21 +254,6 @@ class VideoInfoItem(InfoItem): return d -class HslInfoItem(InfoItem): - """Class for HSL Infoscreen item.""" - - display_name = _("HSL timetables") - - def get_template_url(self): - """Return HSL infoitem template url.""" - return "/static/infoscreen/html/hsl.html" - - @staticmethod - def get_create_template_url(): - """Call create HSL infoitem template url command.""" - return "/static/infoscreen/html/hsl_create.html" - - class ExternalImageInfoItem(InfoItem): """Class for External Image Infoscreen item.""" diff --git a/infoscreen/static/infoscreen/css/hsl.css b/infoscreen/static/infoscreen/css/hsl.css deleted file mode 100644 index 8753ab1..0000000 --- a/infoscreen/static/infoscreen/css/hsl.css +++ /dev/null @@ -1,74 +0,0 @@ -table { - font-size: 4vh; - font-family: 'Droid Sans Mono', monospace; -} -.red { - color: red; - -webkit-animation-name: blinker; - -webkit-animation-duration: 2s; - -webkit-animation-timing-function: linear; - -webkit-animation-iteration-count: infinite; - - -moz-animation-name: blinker; - -moz-animation-duration: 2s; - -moz-animation-timing-function: linear; - -moz-animation-iteration-count: infinite; - - animation-name: blinker; - animation-duration: 2s; - animation-timing-function: linear; - animation-iteration-count: infinite; -} -.black { - color: black; -} -@-moz-keyframes blinker { - 0% { opacity: 1.0; } - 50% { opacity: 0.1; } - 100% { opacity: 1.0; } -} - -@-webkit-keyframes blinker { - 0% { opacity: 1.0; } - 50% { opacity: 0.1; } - 100% { opacity: 1.0; } -} - -@keyframes blinker { - 0% { opacity: 1.0; } - 50% { opacity: 0.1; } - 100% { opacity: 1.0; } -} -thead{ - background: #f0f0f0; -} -.header-row{ - background: #f0f0f0; - font-size: 7vh; - font-family: 'Droid Sans Mono', monospace; - text-align: center; -} - -.container { - width: 100vw; - padding: 0 0 0 0; -} - -.container .table { - margin-left: 0; - margin-right: 0; -} - -.repeat-item.ng-leave { - -} - -.repeat-item.ng-leave.ng-leave-active { - opacity: 0; - font-size: 0vh; -} - -.repeat-item.ng-leave{ - opacity: 1; - font-size: 5vh; -} diff --git a/infoscreen/static/infoscreen/html/coffee.html b/infoscreen/static/infoscreen/html/coffee.html deleted file mode 100644 index 71048e5..0000000 --- a/infoscreen/static/infoscreen/html/coffee.html +++ /dev/null @@ -1,4 +0,0 @@ - - diff --git a/infoscreen/static/infoscreen/html/hsl.html b/infoscreen/static/infoscreen/html/hsl.html deleted file mode 100644 index c804428..0000000 --- a/infoscreen/static/infoscreen/html/hsl.html +++ /dev/null @@ -1,41 +0,0 @@ - - - -
{{clock | date:'HH:mm'}}
| - Aika - | -- Linja - | -- Pysäkki - | -
|---|---|---|
| - {{x.timestamp}} - | -- {{x.route}}, {{x.headsign}} - | -- {{x.stop}} - | -