<commit_before>import xml.etree.ElementTree as ET
import requests


def REQ_GetArrivalAndDepartureTimesForTrip(tripID):
    xml = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetArrivalAndDepartureTimesForTrip", data={'tripID': tripID}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetCurrentBusInfo():
    xml = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetCurrentBusInfo").content
    root = ET.fromstring(xml)
    return root

def REQ_GetCurrentRoutes(tripID):
    xml = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetCurrentRoutes").content
    root = ET.fromstring(xml)
    return root

def REQ_GetNextDepartures(routeShortName, stopCode):
    xml = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetNextDepartures", data={'routeShortName': routeShortName, 'stopCode': stopCode}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetScheduledPatternPoints(patternName):
    xml = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetScheduledPatternPoints", data={'patternName': patternName}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetScheduledRoutes(stopCode):
    xml = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetScheduledRoutes", data={'stopCode': stopCode}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetScheduledStopCodes(stopCode):
    xml = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetScheduledStopCodes", data={'routeShortName': routeShortName}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetScheduledStopNames(stopCode):
    xml = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetScheduledStopNames", data={'routeShortName': routeShortName}).content
    root = ET.fromstring(xml)
    return root

def REQ_GetSummary(stopCode):
    xml = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetSummary").content
    root = ET.fromstring(xml)
    return root

def GetNextDepartureTimesForRouteAndStopCode(routeShortName, stopCode, numTimesToReturn=3):
    results = []

    root = REQ_GetNextDepartures(routeShortName, stopCode)
    for child in root.iter('AdjustedDepartureTime'):
        results.append(child.text)

    sorted(results)

    return results[:numTimesToReturn]


def get_busses_for_stop_code(stopCode):
    root = REQ_GetScheduledRoutes(stopCode)

    results = []

    for child in root.iter('RouteShortName'):
        results.append(child.text)

    return results


def GetTimesForStopCode(stopCode):
    routes = get_busses_for_stop_code(stopCode)

    numTimesToReturn = 1

    if len(routes) <= 2:
        numTimesToReturn = 3

    times = []
    for route in routes:
        times.append( (route, GetNextDepartureTimesForRouteAndStopCode(route, stopCode, numTimesToReturn) ) )

    return times<commit_msg>added exception handling to bt python api<commit_after>import xml.etree.ElementTree as ET
import requests
import pudb

def __req_get_arrival_and_departure_times_for_trip(tripID):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetArrivalAndDepartureTimesForTrip", data={'tripID': tripID})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_current_bus_info():
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetCurrentBusInfo")
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_current_routes(tripID):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetCurrentRoutes")
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_next_departures(routeShortName, stopCode):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetNextDepartures", data={'routeShortName': routeShortName, 'stopCode': stopCode})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_scheduled_pattern_points(patternName):
    exception = None
    try:
        req = requests.post("http://216.252.195.248/webservices/bt4u_webservice.asmx/GetScheduledPatternPoints", data={'patternName': patternName})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_scheduled_routes(stopCode):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetScheduledRoutes", data={'stopCode': stopCode})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_scheduled_stop_codes(stopCode):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetScheduledStopCodes", data={'routeShortName': routeShortName})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_scheduled_stop_names(stopCode):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetScheduledStopNames", data={'routeShortName': routeShortName})
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def __req_get_summary(stopCode):
    exception = None
    try:
        req = requests.post("http://172.16.58.3/webservices/bt4u_webservice.asmx/GetSummary")
    except requests.exceptions.RequestException as e:
        exception = e

    if exception == None:
        content = req.content
        code = req.status_code
        root = ET.fromstring(req.content)
    else:
        code = None
        root = None
        content = None

    return {"status_code": code, "content": content, "xml": root, "exception": exception}

def get_next_departure_times_for_route_and_stop_code(routeShortName, stopCode, numTimesToReturn=3):
    results = []

    resp = __req_get_next_departures(routeShortName, stopCode)
    success = True
    if resp["status_code"] != None and resp["status_code"] == 200:
        for child in resp["xml"].iter('AdjustedDepartureTime'):
            results.append(child.text)
        sorted(results)
    else:
        success = False

    return { "success": success, "status_code": resp["status_code"], "times": results[:numTimesToReturn]}

def get_busses_for_stop_code(stopCode):
    resp = __req_get_scheduled_routes(stopCode)

    route_short_names = []
    route_names = []

    # pudb.set_trace()

    success = True
    if resp["status_code"] != None and resp["status_code"] == 200:
        for child in resp["xml"].iter('RouteShortName'):
            route_short_names.append(child.text)
        for child in resp["xml"].iter('RouteName'):
            route_names.append(child.text)
    else:
        success = False

    return { "success": success, "status_code": resp["status_code"], "route_short_names": route_short_names, "route_names": route_names }


def get_times_for_stop_code(stopCode):
    busses_resp = get_busses_for_stop_code(stopCode)

    times = []
    success = busses_resp["success"]
    if busses_resp["status_code"] != None and busses_resp["status_code"] == 200 and success == True:
        busses = busses_resp["route_short_names"]

        numTimesToReturn = 1

        if len(busses) <= 2:
            numTimesToReturn = 3

        for route in busses:
            next_deps = get_next_departure_times_for_route_and_stop_code(route, stopCode, numTimesToReturn)

            if next_deps["status_code"] != None and next_deps["status_code"] == 200:
                times.append( (route, next_deps["times"] ) )
            else:
                success = False
                break
    else:
        success = False

    return { "success": success, "times": times }
{'fraction_non_alphanumeric': 0.11169641986147692, 'fraction_numerical': 0.020095600429226416, 'mean_word_length': 3.2137279079325936, 'pattern_counts': {'":': 45, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, 'pii_count': 18, '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': '642009', 'n_tokens_mistral': 3305, 'n_tokens_neox': 3152, 'n_words': 637}