<commit_before>import log
import urllib2
import softdog


API_LEVEL_DEV  = 0
API_LEVEL_PRE  = 1
API_LEVEL_PROD = 2

API_VERSION = "1.0"

SERVER_URL_LIST = [
    "http://cr-api.dev-cr.xiaoyezi.com",
    "http://cr-api.pre-cr.xiaoyezi.com",
    "http://cr-api.cr.xiaoyezi.com"
]

def get_server_url(api_level):

    if api_level < 0 or api_level > 2:
        log.e("API_LEVEL: " + api_level + " not correct.")

    return SERVER_URL_LIST[api_level]


def get_current_classroom_info():

    url = get_server_url(API_LEVEL_DEV) \
          + "/api/classroom/1.0/schools/" \
          + softdog.read_soft_dog_data_by_key("schoolCode") \
          + "/classrooms/current"

    log.d("URL: " + url)

    request = urllib2.Request(url)
    request.add_header("XiaoYeZi-Client-Token", softdog.read_soft_dog_data_by_key("token"))
    request.add_header("Content-Type", "application/json")
    request.add_header("Accept", "application/json")
    response = urllib2.urlopen(request)

    if response.getcode() == 200:
        log.e("Get current classroom info success.")
        log.d(response.read())
    else:
        log.e("Get current classroom info failed, return code: " + response.getcode())

    return response.read()


get_current_classroom_info()<commit_msg>Add check current classroom info function<commit_after>import log
import json
import urllib2
import softdog


API_LEVEL_DEV  = 0
API_LEVEL_PRE  = 1
API_LEVEL_PROD = 2

API_VERSION = "1.0"

SERVER_URL_LIST = [
    "http://cr-api.dev-cr.xiaoyezi.com",
    "http://cr-api.pre-cr.xiaoyezi.com",
    "http://cr-api.cr.xiaoyezi.com"
]

def get_server_url(api_level):

    if api_level < 0 or api_level > 2:
        log.e("API_LEVEL: " + api_level + " not correct.")

    return SERVER_URL_LIST[api_level]


def check_request_result(response):

    obj = json.loads(response)
    message = obj["request_result"]["message"]

    if message == "OK":
        log.e("Get current classroom info success.")
    else:
        log.e("Get current classroom info failed: " + message)


def check_get_current_classroom_info():

    api_level = API_LEVEL_DEV

    url = get_server_url(api_level) \
          + "/api/classroom/1.0/schools/" \
          + softdog.read_soft_dog_data_by_key("schoolCode") \
          + "/classrooms/current"

    log.d("URL: " + url)

    request = urllib2.Request(url)
    request.add_header("XiaoYeZi-Client-Token", softdog.read_soft_dog_data_by_key("token"))
    request.add_header("Content-Type", "application/json")
    request.add_header("Accept", "application/json")
    response = urllib2.urlopen(request)

    if response.getcode() == 200:
        log.e("Can communicate with Server: " + get_server_url(api_level))
        check_request_result(response.read())
    else:
        log.e("Get current classroom info failed, return code: " + response.getcode())


check_get_current_classroom_info()
{'fraction_non_alphanumeric': 0.1333565459610028, 'fraction_numerical': 0.010445682451253482, 'mean_word_length': 3.353030303030303, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, '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': '4279685', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1003, 'n_words': 171}