<commit_before>from flask import Flask
import datetime
import json
import requests
import base64
from api_keys import API
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/vasttrafik/<id>')
def vasttrafik(id=None):
    return getVasttrafikJSON(id)

def getVasttrafikJSON(id):
    authKey = getAccsessTokenVasttrafik()
    date = '20' + str(datetime.datetime.now().strftime("%y-%m-%d"))
    time = str(datetime.datetime.now().strftime("%H:%M"))
    host = 'https://api.vasttrafik.se'
    baseurl = '/bin/rest.exe/v2'
    request = {
        'id': id,
        'date': date,
        'time': time,
        'authKey': authKey,
        'format': 'json',
    }
    requestURL = host + baseurl + '/departureBoard'
    r = requests.get(requestURL, params=request)
    return r.json()

def getAccsessTokenVasttrafik():
    url = 'https://api.vasttrafik.se/token' # Set destination URL here
    key = API['vasttrafik']['key']
    secret = API['vasttrafik']['secret']
    encoded = base64.b64encode((key + ":" + secret).encode()).decode()
    post_fields = {
        'grant_type': 'client_credentials',
        'scope': '1'
    }
    headers = {
        'Authorization': 'Basic ' + encoded,
        'Content-Type': 'application/x-www-form-urlencoded',
    }     # Set POST fields here
    r = requests.post(url, data=post_fields, headers=headers).json()
    r = json.dumps(r)
    access_token = json.loads(r)['access_token']<commit_msg>successfully get data from the Västrafik API<commit_after>from flask import Flask
import datetime
import json
import requests
import base64
from api_keys import API
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/vasttrafik/<id>')
def vasttrafik(id=None):
    return getVasttrafikJSON(id)

def getVasttrafikJSON(id):
    authKey = getAccsessTokenVasttrafik()
    date = '20' + str(datetime.datetime.now().strftime("%y-%m-%d"))
    time = str(datetime.datetime.now().strftime("%H:%M"))
    host = 'https://api.vasttrafik.se'
    baseurl = '/bin/rest.exe/v2'
    headers = {
        'Authorization': 'Bearer ' + authKey
    }
    request = {
        'id': id,
        'date': date,
        'time': time,
        'format': 'json',
    }
    requestURL = host + baseurl + '/departureBoard'
    r = requests.get(requestURL, params=request, headers=headers)
    return json.dumps(r.json())

def getAccsessTokenVasttrafik():
    url = 'https://api.vasttrafik.se/token' # Set destination URL here
    key = API['vasttrafik']['key']
    secret = API['vasttrafik']['secret']
    encoded = base64.b64encode((key + ":" + secret).encode()).decode()
    post_fields = {
        'grant_type': 'client_credentials',
        'scope': '1'
    }
    headers = {
        'Authorization': 'Basic ' + encoded,
        'Content-Type': 'application/x-www-form-urlencoded',
    }     # Set POST fields here
    r = requests.post(url, data=post_fields, headers=headers).json()
    r = json.dumps(r)
    access_token = json.loads(r)['access_token']
{'fraction_non_alphanumeric': 0.16026272577996717, 'fraction_numerical': 0.006568144499178982, 'mean_word_length': 3.2541899441340782, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2307547', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1040, 'n_words': 208}