Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: UTF-8 -*-
- import cgi, cgitb, json
- import sys, os
- cgitb.enable(format="text")
- filename = "test.json"
- print ("Content-type: application/json")
- print ()
- method = os.environ['REQUEST_METHOD']
- if method == "GET":
- f = open(filename, "r")
- data = f.read()
- print(data)
- f.close()
- else:
- content_length = int(os.environ['CONTENT_LENGTH'])
- data = sys.stdin.read(content_length)
- data_json = json.loads(data)
- fileLug = open(filename, "r")
- lugemine = json.load(fileLug)
- lugemine["userdata"].append(data_json)
- fileLug.close()
- fileWrite = open(filename, "w")
- json.dump(lugemine, fileWrite)
- fileWrite.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement