#!/usr/bin/python3
# -*- coding: UTF-8 -*-
print ("Content-Type: text/html;charset=utf-8\n\r\n\r")
# enable debugging
import cgitb
cgitb.enable()
import cgi
form = cgi.FieldStorage()
import os
import shutil
import json
fileSystem = "/home/jesseorg/public_html/www.entropynetwork.com"
webURL = "/"
print ("File a graph into " + fileSystem)
out = form.getvalue("fileURL")
print ("got")
#print (out.encode('utf-8') )
out2 = out.encode('utf-8')
print ("type: ")
print (type(out2) )
#print (out2.decode("utf-8") )
#print (out2.decode('utf8'))
#print ("
选中的网站是 %s
" % out)
theJSON = {}
#sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
## If you need input too, read from char_stream as you would sys.stdin
#char_stream = codecs.getreader('utf-8')(sys.stdin)
#cgitb.enable()
def getForm():
print ("
getForm")
if form.getfirst("data") != None:
print ("
data")
global theJSON, theJSON2
theJSON = form.getvalue("data")
print ("g:data")
theJSON2 = theJSON.encode('utf-8')
print ("
nodes: ")
print (theJSON2 )
if form.getvalue("fileURL") != None:
global fileURL,fileURL2
fileURL = form.getvalue("fileURL")
print ("g:fileURL")
fileURL2 = fileURL.encode('utf-8')
print ("
fileURL: ")
print(fileURL2)
if form.getvalue("stem") != None:
global stem,stem2
stem = form.getvalue("stem")
print ("g:stem")
stem2 = stem.encode('utf-8')
#stem=stem2.decode('utf-8')
print ("
stem")
print (stem2)
#return (theJSON, fileURL, stem)
getForm()
#print ("
look" + str(theJSON) )
if theJSON != None:
prepURL = fileSystem + "/" + fileURL+"/"+stem+".json"
print ("
saved "+prepURL+ " "+stem+"")
tJSON = json.loads(theJSON)
#print (str(tJSON) + " END")
json_dump = json.dumps(tJSON)
# print(json_dump)
fj = open(prepURL, "w")
print(json_dump, file=fj)
fj.close()