Skip to content

Instantly share code, notes, and snippets.

@hamzakat
Created January 8, 2022 05:29
Show Gist options
  • Select an option

  • Save hamzakat/6dd9fd24b0cc531cbdcef1347e60a00c to your computer and use it in GitHub Desktop.

Select an option

Save hamzakat/6dd9fd24b0cc531cbdcef1347e60a00c to your computer and use it in GitHub Desktop.

Revisions

  1. hamzakat created this gist Jan 8, 2022.
    27 changes: 27 additions & 0 deletions txt_to_json_and_post.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #! /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()