I'm really new to Python, and I am trying to create a script that appends JSON to the end of a pre-existing JSON file. The way my server runs is that it only executes Python folders in the cgi-bin folder (public_html/cgi-bin).
I have the JSON file and the Python script file in the same directory and attempt to alter it with the following code:
#!/usr/bin/env python
import cgi
import json
new_data = {"2": {"title": "what", "date": "tomorrow"}}
print("Content-type: application/json\n\r")
with open("jobs.json") as file:
data = json.load(file)
data.update(new_data)
with open('jobs.json', 'w') as file:
json.dump(data, file)
But when I load that page nothing happens, jobs.json
stays the same.
I talked to my server provider and they said that JSON files in the cgi-bin are considered just being in public_html (if I access them there in my address bar, it finds it fine, whereas it doesn't in the cgi-bin directory). Then how do I access users.json
if it's apparently back at public_html?
The path to the Python file is /public_html/ooproject/two.py
and jobs.json
is in that same directory.