Created
January 8, 2022 05:29
-
-
Save hamzakat/6dd9fd24b0cc531cbdcef1347e60a00c to your computer and use it in GitHub Desktop.
Convert txt files to JSON, then POST all the JSONs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import os | |
import requests as req | |
import json | |
data_dir = "/data/feedback" | |
feedbacks = [] | |
for file in os.listdir(data_dir): | |
file_path = os.path.join(data_dir, file) | |
if os.path.isfile(file_path): | |
with open(file_path) as file: | |
file_list = file.read().splitlines() | |
feedback_dict = {"title": file_list[0],"name": file_list[1],"date": file_lis$ | |
feedbacks.append(feedback_dict) | |
for f in feedbacks: | |
print(f) | |
print(type(f)) | |
res = req.post("http://34.69.132.48/feedback", json=f) | |
res.raise_for_status() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment