import requests
requests.packages.urllib3.disable_warnings() 
from icecream import ic

token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJlZ3VsYXJAaXRlYy5hYXUuYXQiLCJjcmVhdGVkX2F0IjoiMjAyMS0wMy0yNCAxMDoxMzo1MS4wMjkwNDkiLCJ2YWxpZF91bnRpbCI6IjIwMjEtMDMtMjUgMTA6MTM6NTEuMDI5MDQ5In0.V6kYV5Lmb_tUIsF-6AKNB8_lIifmJP_Dm8gHhGa5w_o'

def httpget(url):
    res = requests.get(url, 
                    verify=False, 
                    headers = { "Authorization": f"Bearer {token}"})
    return res

res_f = httpget(url = 'https://articonf1.itec.aau.at:30001/api/use_cases/crowd-journalism/transactions-failed')

failed_purchases = []
for entry in res_f.json():
    if entry['docType'] == 'purchase':
        failed_purchases.append(entry)

print(len(failed_purchases))


# upload again
def httppost_gateway(content_):
    url = 'https://articonf1.itec.aau.at:30401/api/trace'
    res = requests.post(url, 
                    verify=False, 
                    headers = { "Authorization": f"Bearer {token}"},
                    json=content_)
    return res

for purchase in failed_purchases:
    res = httppost_gateway(purchase)
    print(res)