Skip to content

Instantly share code, notes, and snippets.

@wiljdaws
Created August 9, 2023 19:23
Show Gist options
  • Save wiljdaws/ee66829c06c5c7d185771260d02ecc03 to your computer and use it in GitHub Desktop.
Save wiljdaws/ee66829c06c5c7d185771260d02ecc03 to your computer and use it in GitHub Desktop.
Post Json Data
#! /usr/bin/env python3
import os
import requests
directory = "/data/feedback"
for filename in os.listdir(directory):
if filename.endswith(".txt"):
with open(os.path.join(directory, filename)) as file:
lines = file.readlines()
title = lines[0].strip()
name = lines[1].strip()
date = lines[2].strip()
feedback = lines[3].strip()
data = {"title": title, "name": name, "date": date, "feedback": feedback}
res = requests.post("http://35.233.238.127/feedback/", data=data)
print("status_code ",res.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment