import sys
{% include 'macroheader.py.template' %}

def run_macro(args):
    # Get IDs of in-context requests
    reqids = main_context_ids()
    reqids.reverse() # Resubmit earliest first
    reqs = []

    # Create session jar (uncomment jar functions to use)
    #jar = Session() # Create a cookie jar

    # Iterate over each request and submit it
    for rid in reqids:
        print rid,
        sys.stdout.flush()
        r = request_by_id(rid)
        r = r.copy()

        #jar.apply_req(r) # Apply headers/cookies from the cookie jar

        #####################
        # Modify request here
        
        r.submit()
        #jar.save_rsp(r.response, save_all=True) # Update the cookie jar from the response

        #r.save() # Save the request to the data file
        reqs.append(r)

    print ''

    # Store the requests in memory
    set_tag('resubmit', reqs)