From 0a1708d7aaeb3239202336af7e9fb86425e28099 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Fri, 5 Apr 2019 22:36:11 +0200 Subject: [PATCH] traffic scraper mostly done --- server/nightr/scrape.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/server/nightr/scrape.py b/server/nightr/scrape.py index f985acb..559bcce 100644 --- a/server/nightr/scrape.py +++ b/server/nightr/scrape.py @@ -1,8 +1,32 @@ import requests +import json +import os + def scrape_traffic(): r = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=b3eeb0ff-c8a8-4824-99d6-e0a3747c8b0d') + night_avr = 3.38 + day_avr = None + data = r.json() - print(data) + sum = 0 + len = 0 + for lel in data['result']['records']: + sum += lel['vehicleCount'] + len += 1 + curr_avg = len / sum + + diff= day_avr - night_avr + + if curr_avg >= day_avr: + return 0.0 + elif curr_avg <= night_avr: + return 1.0 + res = 1 - curr_avg / diff + + assert(res < 1 and res > 0) + + return res + scrape_traffic() \ No newline at end of file