<commit_before>import emission.core.get_database as edb
import bson.json_util as bju
import requests
import json
import logging

# Request data for the specified phones and time range
def request_data(server_url, from_ts, to_ts, phone_ids, debug):
	url = server_url + "/eval/publicData/timeseries?from_ts=" + str(from_ts) + "&to_ts=" + str(to_ts)
	ids = {'phone_ids': phone_ids}
	headers = {'Content-Type': 'application/json'}

	r = requests.get(url, data=json.dumps(ids), headers = headers)

	dic = json.loads(r.text, object_hook = bju.object_hook)
	phone_list = dic['phone_data']

	if phone_list == None:
		print "Requested amount of data exceeds the threshold value."
	else:  
		# Load data to the local server 
		tsdb = edb.get_timeseries_db()

		for index, entry_list in enumerate(phone_list):
			if debug:
				logging.debug("phone" + str(index+1) + " first entry (in Pacific Time):")

				if len(entry_list) == 0:
					logging.debug("...has no data...")
				else:
					logging.debug(str(entry_list[0]))

			for entry in entry_list:
				tsdb.save(entry)


# Request data in 5hr-long chunks
def request_batched_data(server_url, from_ts, to_ts, phone_ids):
	t1 = from_ts
	debug = True # only set to True for the first loop iteration 
	while t1 < to_ts:
		t2 = min(t1 + 5*60*60, to_ts)
		request_data(server_url, t1, t2, phone_ids, debug)
		t1 = t2 
		debug = False
	print "Data loaded to local server!"<commit_msg>fixed logging message<commit_after>import emission.core.get_database as edb
import bson.json_util as bju
import requests
import json
import logging

# Request data for the specified phones and time range
def request_data(server_url, from_ts, to_ts, phone_ids, debug):
	url = server_url + "/eval/publicData/timeseries?from_ts=" + str(from_ts) + "&to_ts=" + str(to_ts)
	ids = {'phone_ids': phone_ids}
	headers = {'Content-Type': 'application/json'}

	r = requests.get(url, data=json.dumps(ids), headers = headers)

	dic = json.loads(r.text, object_hook = bju.object_hook)
	phone_list = dic['phone_data']

	if phone_list == None:
		print "Requested amount of data exceeds the threshold value."
	else:  
		# Load data to the local server 
		tsdb = edb.get_timeseries_db()

		for index, entry_list in enumerate(phone_list):
			if debug:
				logging.debug("phone" + str(index+1) + " first entry (in Pacific Time):")

				if len(entry_list) == 0:
					logging.debug("...has no data...")
				else:
					logging.debug(str(entry_list[0].get('metadata').get('write_fmt_time')))

			for entry in entry_list:
				tsdb.save(entry)


# Request data in 5hr-long chunks
def request_batched_data(server_url, from_ts, to_ts, phone_ids):
	t1 = from_ts
	debug = True # only set to True for the first loop iteration 
	while t1 < to_ts:
		t2 = min(t1 + 5*60*60, to_ts)
		request_data(server_url, t1, t2, phone_ids, debug)
		t1 = t2 
		debug = False
	print "Data loaded to local server!"
{'fraction_non_alphanumeric': 0.11805555555555555, 'fraction_numerical': 0.011805555555555555, 'mean_word_length': 4.228675136116152, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2828428', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1003, 'n_words': 291}