<commit_before>import os
import datetime
import requests

from flask import jsonify, request
from dateutil.parser import parse

from server import app, db, sqldb
from penn.base import APIError
from ..models import StudySpacesBooking, User
from ..penndata import studyspaces, wharton
from ..base import cached_route


@app.route('/studyspaces/availability/<int:building>', methods=['GET'])
def parse_times(building):
    """
    Returns JSON containing all rooms for a given building.

    Usage:
        /studyspaces/availability/<building> gives all rooms for the next 24 hours
        /studyspaces/availability/<building>?start=2018-25-01 gives all rooms in the start date
        /studyspaces/availability/<building>?start=...&end=... gives all rooms between the two days
    """
    if 'date' in request.args:
        start = request.args.get('date')
        end = request.args.get('date')
    else:
        start = request.args.get('start')
        end = request.args.get('end')

    if building == 1:
        sessionid = get_wharton_sessionid(public=True)
        try:
            rooms = wharton.get_wharton_gsrs(sessionid, date=start)
            rooms = wharton.switch_format(rooms)
            save_wharton_sessionid()
        except APIError as e:
            return jsonify({"error": str(e)}), 400
    else:
        try:
            rooms = studyspaces.get_rooms(building, start, end)
            rooms["location_id"] = rooms["id"]
            rooms["rooms"] = []
            for room_list in rooms["categories"]:
                for room in room_list["rooms"]:
                    room["thumbnail"] = room["image"]
                    del room["image"]
                    room["room_id"] = room["id"]
                    del room["id"]
                    room["gid"] = room_list["cid"]
                    room["lid"] = building
                    room["times"] = room["availability"]
                    del room["availability"]
                    for time in room["times"]:
                        time["available"] = True
                        time["start"] = time["from"]
                        time["end"] = time["to"]
                        del time["from"]
                        del time["to"]
                    rooms["rooms"].append(room)
        except APIError as e:
            return jsonify({"error": str(e)}), 400
    return jsonify(rooms)


@app.route('/studyspaces/locations', methods=['GET'])
def display_id_pairs():
    """
    Returns JSON containing a list of buildings with their ids.
    """
    def get_data():
        return {"locations": studyspaces.get_buildings() + [{"lid": 1, "name": "<NAME>", "service": "wharton"}]}

    return cached_route('studyspaces:locations', datetime.timedelta(days=1), get_data)
<commit_msg>added mising func<commit_after>import os
import datetime
import requests

from flask import jsonify, request
from dateutil.parser import parse

from server import app, db, sqldb
from penn.base import APIError
from ..models import StudySpacesBooking, User
from ..penndata import studyspaces, wharton
from ..base import cached_route
from .book import get_wharton_sessionid, save_wharton_sessionid


@app.route('/studyspaces/availability/<int:building>', methods=['GET'])
def parse_times(building):
    """
    Returns JSON containing all rooms for a given building.

    Usage:
        /studyspaces/availability/<building> gives all rooms for the next 24 hours
        /studyspaces/availability/<building>?start=2018-25-01 gives all rooms in the start date
        /studyspaces/availability/<building>?start=...&end=... gives all rooms between the two days
    """
    if 'date' in request.args:
        start = request.args.get('date')
        end = request.args.get('date')
    else:
        start = request.args.get('start')
        end = request.args.get('end')

    if building == 1:
        sessionid = get_wharton_sessionid(public=True)
        try:
            rooms = wharton.get_wharton_gsrs(sessionid, date=start)
            rooms = wharton.switch_format(rooms)
            save_wharton_sessionid()
        except APIError as e:
            return jsonify({"error": str(e)}), 400
    else:
        try:
            rooms = studyspaces.get_rooms(building, start, end)
            rooms["location_id"] = rooms["id"]
            rooms["rooms"] = []
            for room_list in rooms["categories"]:
                for room in room_list["rooms"]:
                    room["thumbnail"] = room["image"]
                    del room["image"]
                    room["room_id"] = room["id"]
                    del room["id"]
                    room["gid"] = room_list["cid"]
                    room["lid"] = building
                    room["times"] = room["availability"]
                    del room["availability"]
                    for time in room["times"]:
                        time["available"] = True
                        time["start"] = time["from"]
                        time["end"] = time["to"]
                        del time["from"]
                        del time["to"]
                    rooms["rooms"].append(room)
        except APIError as e:
            return jsonify({"error": str(e)}), 400
    return jsonify(rooms)


@app.route('/studyspaces/locations', methods=['GET'])
def display_id_pairs():
    """
    Returns JSON containing a list of buildings with their ids.
    """
    def get_data():
        return {"locations": studyspaces.get_buildings() + [{"lid": 1, "name": "<NAME>", "service": "wharton"}]}

    return cached_route('studyspaces:locations', datetime.timedelta(days=1), get_data)

{'fraction_non_alphanumeric': 0.1247327156094084, 'fraction_numerical': 0.0067712045616536, 'mean_word_length': 2.1551433389544687, 'pattern_counts': {'":': 12, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4493470', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1497, 'n_words': 403}