<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import datetime
from django.conf import settings
from django.http import HttpResponse

import json
from ..utilities.thebus.client import parse_xml_to_dict
from ..utilities.thebus.client import TheBusClient
from ..utilities.time.utilities import naive_to_timestamp


def bus_details(request, bus):
    c = TheBusClient(settings.THEBUS_API_CLIENT_TOKEN)
    v_json = c.track_vehicle(int(bus), parse_xml_to_dict)
    vehicles = v_json.get('vehicles', None)
    vehicle = vehicles.get('vehicle', None)

    if 'last_message' in vehicle:
        naive_datetime = datetime.datetime.strptime(
            vehicle['last_message'],
            "%m/%d/%Y %I:%M:%S %p")
        vehicle['last_message_ts'] = naive_to_timestamp(
            naive_datetime, tz='Pacific/Honolulu')

    return HttpResponse(json.dumps(vehicle), mimetype="application/json")

# vim: filetype=python<commit_msg>Raised 404 if can't get vehicle from the client<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import datetime
from django.conf import settings
from django.http import Http404
from django.http import HttpResponse

import json
from ..utilities.thebus.client import parse_xml_to_dict
from ..utilities.thebus.client import TheBusClient
from ..utilities.time.utilities import naive_to_timestamp


def bus_details(request, bus):
    c = TheBusClient(settings.THEBUS_API_CLIENT_TOKEN)
    v_json = c.track_vehicle(int(bus), parse_xml_to_dict)
    vehicles = v_json.get('vehicles', None)
    vehicle = vehicles.get('vehicle', None)

    if vehicle:
        if 'last_message' in vehicle:
            naive_datetime = datetime.datetime.strptime(
                vehicle['last_message'],
                "%m/%d/%Y %I:%M:%S %p")
            vehicle['last_message_ts'] = naive_to_timestamp(
                naive_datetime, tz='Pacific/Honolulu')

        return HttpResponse(json.dumps(vehicle), mimetype="application/json")
    else:
        raise Http404("Unable to find Bus {}".format(str(bus)))

# vim: filetype=python
{'fraction_non_alphanumeric': 0.11493695441319107, 'fraction_numerical': 0.00533462657613967, 'mean_word_length': 3.6886363636363635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6703092', 'n_tokens_mistral': 666, 'n_tokens_neox': 633, 'n_words': 142}