<commit_before>"""
Uploads the current version of ok.py to the server.
"""

import requests
import base64
from os import path
import json

SERVER_URL = 'https://ok-server.appspot.com/api/v1/assignment'
#SERVER_URL = 'http://localhost:8080/api/v1/assignment'

def get_current_templates(assign_name):
    resp = requests.get(SERVER_URL + "?name=" + assign_name)
    results = resp.json()['data']['results'][0]
    return results['id'], results['templates']

def main():
    assign_name = raw_input("Please input the assignment name: ")

    params = {
        'access_token': raw_input("Please enter your access token:")
    }

    assign_id, current_templates = get_current_templates(assign_name)

    try:
        current_templates = json.loads(current_templates)
    except ValueError:
        current_templates = {}

    in_str = True

    while in_str:
        in_str = raw_input("Enter filename to upload, or \"done\" to upload: ")
        if in_str == "done":
            break
        else:
            with open(in_str) as f:
                current_templates[path.basename(in_str)] = f.read()

    data = {
        'templates': current_templates
    }
    headers = {'content-type': 'application/json'}

    data = json.dumps(data)
    resp = requests.put(SERVER_URL + '/%s' % assign_id, params=params, data=data, headers=headers)
    print resp

if __name__ == "__main__":
    main()<commit_msg>Allowed upload template to handle empty default templates.<commit_after>"""
Uploads the current version of ok.py to the server.
"""

import requests
import base64
from os import path
import json

SERVER_URL = 'https://ok-server.appspot.com/api/v1/assignment'
#SERVER_URL = 'http://localhost:8080/api/v1/assignment'

def get_current_templates(assign_name):
    resp = requests.get(SERVER_URL + "?name=" + assign_name)
    results = resp.json()['data']['results'][0]
    return results['id'], results['templates']

def main():
    assign_name = raw_input("Please input the assignment name: ")

    params = {
        'access_token': raw_input("Please enter your access token:")
    }

    assign_id, current_templates = get_current_templates(assign_name)

    current_templates = {}
    try:
        if isinstance(current_templates, str):
            current_templates = json.loads(current_templates)
    except ValueError:
        current_templates = {}

    in_str = True

    while in_str:
        in_str = raw_input("Enter filename to upload, or \"done\" to upload: ")
        if in_str == "done":
            break
        else:
            with open(in_str) as f:
                current_templates[path.basename(in_str)] = f.read()

    data = {
        'templates': current_templates
    }
    headers = {'content-type': 'application/json'}

    data = json.dumps(data)
    resp = requests.put(SERVER_URL + '/%s' % assign_id, params=params, data=data, headers=headers)
    print resp

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.12350733538041624, 'fraction_numerical': 0.006141248720573183, 'mean_word_length': 3.1237693389592125, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3186074', 'n_tokens_mistral': 900, 'n_tokens_neox': 884, 'n_words': 218}