<commit_before># API calls on theia.media.mit.edu in a handy module
# Author: <NAME>
# Using python since it's easier to put on the rPI
import requests		# pip install requests if you don't have it 
import json

# Get the key from external file
keyfile = open('key')
key = keyfile.readline()

def grade_request(file):
    # makes the request to the theia interface and returns the grade of that image.
	# if there is something wrong, it returns -1
	# argument - file object
	uri = 'https://theia.media.mit.edu/api/v1/uploadImage?key=' + key
	response = requests.post(uri, files={'file': file})
	
	if (response.status_code == 200):
		# print "response OK"
		# convert response.text to json and parse as dictionary
		data = json.loads(response.text)
		grade = float(str(data['grade'])[1:-1])
		return grade
	else:
		return -1

## BEGIN THE REQUEST:
# print grade_request(open('normal1.jpg', 'rb'))<commit_msg>added key check in theia.py, need to also add bad api key check in repsonse from server<commit_after># API calls on theia.media.mit.edu in a handy module
# Author: <NAME>
# Using python since it's easier to put on the rPI
import requests		# pip install requests if you don't have it 
import json

key = ''
# Get the key from external file
try:
    keyfile = open('key')
    key = keyfile.readline()
except IOError:
    print "CANNOT FIND KEY FOR THEIA. PLEASE CHECK."

def grade_request(file):
    # makes the request to the theia interface and returns the grade of that image.
	# if there is something wrong, it returns -1
	# argument - file object
	uri = 'https://theia.media.mit.edu/api/v1/uploadImage?key=' + key
	response = requests.post(uri, files={'file': file})
	
	if (response.status_code == 200):
                # TODO: check for BAD API KEY
		# print "response OK"
		# convert response.text to json and parse as dictionary
		data = json.loads(response.text)
		grade = float(str(data['grade'])[1:-1])
		return grade
	else:
		return -1


## BEGIN THE REQUEST:
# print grade_request(open('normal1.jpg', 'rb'))
{'fraction_non_alphanumeric': 0.11116600790513834, 'fraction_numerical': 0.008893280632411068, 'mean_word_length': 3.775943396226415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1658174', 'n_tokens_mistral': 661, 'n_tokens_neox': 633, 'n_words': 246}