#from concurrent.futures import ThreadPoolExecutor
from oeem_uploader.request import Request

def upload_consumption(records):
    """
    Takes in a list of consumption records, uploads
    to the configured oee datastore.
    """
    group_records_by_project
    group_by_consumption_metadata
    #  Itertools group-by
    for project, fuel_type, records in groups:
        if projec_exists(project):
            metadata = get_or_create_metadata(fuel_type)
            response = post_consumption_records(project, metadata, records)
            process_response(response)

def process_response():
    pass


def upload_record(record, request):
    return request.post('projects', data=record)


def upload_projects(records):
    """
    Takes in a list of projects,
    uploads them to the configured datastore.
    """
    ### functionalize and map this rather than for loop
    request = Request()
    for record in records:
        r = upload_record(record, request)
        if r.status_code == 200:
            pass
        else:
            attempt_update_project(record)

def attempt_update_project(project):
    """
    Takes a project and attempts an UPDATE
    """
    get_project_from_server 
    if projects == same():
        pass 
        """log(already online)"""
    else:
        if should_i_update():
            project.update()

def should_project_update(project):
    """
    Returns True/False if a project should
    HTTP update or not. 
    """
    pass


@@ -612,89 +612,2134 @@
 def 
-upload_record(record
+get_or_create(item_name, extra_info, get_url, create_url, data):%0A%0A%0A    response = Request.get(get_url)%0A%0A    if response.status_code != 200:%0A        message = %22GET error (%7B%7D): %7B%7D%5Cn%7B%7D%22.format(%0A                response.status_code, get_url, response.text)%0A        raise ValueError(message)%0A%0A    pks = %5Bitem%5B%22id%22%5D for item in response.json()%5D%0A%0A    if pks == %5B%5D:%0A        response = Request.post(create_url,%0A                                data)%0A%0A        if response.status_code != 201:%0A            message = %22Create POST error (%7B%7D): %7B%7D%5Cn%7B%7D%5Cn%7B%7D%22.format(%0A                    response.status_code
 , 
+c
 re
-quest):%0A    return request.post('projects', data=record)%0A
+ate_url, data, response.text)%0A            raise ValueError(message)%0A%0A        pk = response.json()%5B%22id%22%5D%0A%0A        if verbose:%0A            print(%22Created %7B%7D (%7B%7D, pk=%7B%7D)%22.format(item_name, extra_info, pk))%0A%0A        return pk, True%0A    else:%0A        pk = pks%5B0%5D%0A%0A        if len(pks) %3E 1:%0A            message = (%0A                %22Found multiple %7B%7D instances (%7B%7D) for %7B%7D; using pk=%7B%7D%22%0A                .format(item_name, pks, extra_info, pk)%0A            )%0A            warnings.warn(message)%0A%0A        if verbose:%0A            print(%22Existing %7B%7D (%7B%7D, pk=%7B%7D)%22.format(item_name, extra_info, pk))%0A%0A        return pk, False%0A%0Adef get_or_create_project(project_id, project_owner_id,%0A        baseline_period_start, baseline_period_end,%0A        reporting_period_start, reporting_period_end,%0A        latitude, longitude, zipcode, weather_station, url, token, verify=True):%0A%0A    get_url = url + PROJECT_URL + %22?project_id=%7B%7D%22.format(project_id)%0A    create_url = url + PROJECT_URL%0A%0A    data = %7B%0A        %22project_id%22: project_id,%0A        %22project_owner%22: project_owner_id,%0A        %22baseline_period_start%22: baseline_period_start,%0A        %22baseline_period_end%22: baseline_period_end,%0A        %22reporting_period_start%22: reporting_period_start,%0A        %22reporting_period_end%22: reporting_period_end,%0A        %22latitude%22: latitude,%0A        %22longitude%22: longitude,%0A        %22zipcode%22: zipcode,%0A        %22weather_station%22: weather_station,%0A    %7D%0A%0A%0A    return get_or_create(%22Project%22, project_id, get_url, create_url, data,%0A            token, verify=True, verbose=True)
 %0A%0Ade
@@ -2984,37 +2984,36 @@
 r = 
-upload_record(record, request
+get_or_create_project(record
 )%0A  

update functions from etl