Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # -*- coding: UTF-8 -*-
  4.  
  5. import cgi, cgitb, json
  6. import sys, os
  7. cgitb.enable(format="text")
  8.  
  9. filename = "test.json"
  10.  
  11. print ("Content-type: application/json")
  12. print ()
  13.  
  14. method = os.environ['REQUEST_METHOD']
  15. if method == "GET":
  16. f = open(filename, "r")
  17.  
  18. data = f.read()
  19. print(data)
  20.  
  21. f.close()
  22.  
  23. else:
  24. content_length = int(os.environ['CONTENT_LENGTH'])
  25. data = sys.stdin.read(content_length)
  26. data_json = json.loads(data)
  27. fileLug = open(filename, "r")
  28. lugemine = json.load(fileLug)
  29. lugemine["userdata"].append(data_json)
  30. fileLug.close()
  31.  
  32.  
  33. fileWrite = open(filename, "w")
  34.  
  35. json.dump(lugemine, fileWrite)
  36.  
  37. fileWrite.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement