-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
31 lines (24 loc) · 1.01 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import requests, os
from collections import OrderedDict
import json
def main():
# get the files from source directory
text_files = os.listdir("/data/feedback")
# process the text files one by one
for text_file in text_files:
# initialize the dictionary to store feedback data inside
dictionary = OrderedDict()
# read the contents of the file, and insert them into the dictionary
with open("/data/feedback/" + text_file, "r") as file:
dictionary['title'] = file.readline().strip("\n")
dictionary['name'] = file.readline().strip("\n")
dictionary['date'] = file.readline().strip("\n")
dictionary['feedback'] = ''.join([ line.strip("\n") for line in file.readlines()])
# make the request to the website
upload_request = requests.post("http://34.133.161.90/feedback/", json=dictionary)
# check status code
if not upload_request.status_code == 201:
print("Error uploading /data/feedback/" + os.path.basename(text_file) + " :: status code:$
if __name__ == "__main__":
main()