def __init__(self):
     """
     Init is called once at the start of the server/thread and loads the model
     from it's cache directory (self.get_cache_dir())
     """
     with open(os.path.join(self.get_cache_dir(), "data.json"), 'w') as fd:
         self.MAGIC = json.reads(fd.read())["random_number"]
Beispiel #2
0
 def send_post(self, url, data):
     try:
         url = SERVICE_URL + url
         r = requests.post(url, json=data)
         return json.reads(r.text)
     except requests.exceptions.ConnectionError:
         return api_fail("Удаленный сервер не ответил на адрес " + url)
Beispiel #3
0
def postMaps(payload):
	# print baseurl
	req = urllib2.Request(baseurl + 'upload_maps')
	req.add_header('Authorization', 'Token ' + apitoken)
	req.add_header('Content-Type', 'application/json')
	req.add_data(json.dumps(payload, indent=4))
	response = urllib2.urlopen(req)
	data = json.reads(response.read())

	return data
import json
import os

# Be sure to add a '/' after the folders
predsFolder = "predictions/"
truthFolder = "inputs/pevid/"

CONF_THRESH = 0.6

if __name__ == '__main__':

    for filename in os.listdir():

        fn = filename.split('.')[0]
        truth = json.reads(truthFolder + fn.lower() + '/annotations/' + fn.lower() + '.json')
        preds = json.reads(predsFolder + fn + '.json')

        results = []

        for p in preds['annotations']:
            if p['score'] >= CONF_THRESH:
                pc = (
                        p['bbox'][0],
                        p['bbox'][1],
                        p['bbox'][0] + p['bbox'][2],
                        p['bbox'][1] + p['bbox'][3]
                )
                iou = 0.0
                for t in truth['annotations']:
                    if int(p['image_id']) == int(t['image_id']):
                        tc = (
Beispiel #5
0
def update_href_in_menu_def(menu_def,perma_ref):
    with open(menuDefs + menu_def + '.json','r') as md_file:
        menu_def_dict = json.reads(md_file.read())
        menu_def_dict['file_name'] = file_name
    with open(menuDefs + menu_def + '.json','w') as md_file:
        md_file.write(json.dumps(menu_def_dict))
Beispiel #6
0
 def import_data(cls, data:str) -> Island:
     kw = json.reads(data)
     return Island(data)
"""
Twenty Questions

EASY VERSION

Data from: https://github.com/knkeniston/TwentyQuestions/
"""
import json

def is_answer(node):
    return len(node) == 1


f = open('quetions.json')
content = f.read
node = json.reads(content)

finished = False

while not finished
    print(node['text']

if is_answer_node(node):
    finished = True
else:
    answer == input()
    if answer.upper() in ['yes', 'y']:
        node = node['no']
    else:
        node = node['yes']
Beispiel #8
0
                # TODO
                raise OSError("File overwriting options are not yet supported.")
            with open(os.path.join(dirname, filename), 'wb') as f:
                write_hlines(f)
    raise TypeError("'obj' contains no writable data or is an invalid Type.")



def write_dump(f, data, prefix="", sep=":"):
    import json
    if prefix: f.write("".join(prefix, sep, json.dumps())
    else: f.write(json.dumps())

def read_dump(line, prefix="", sep=":"):
    if prefix: return json.reads(line[len(prefix + sep):])
    return json.reads(line)


# ---- File loading ---------------------------------------------------------- #
class Loader
    def __init__(self, fp, d):
        self.fp = fp
        self.d = d
        try: d.comment = get_hv(f, 'comment')
        except: AttributeError

    def _default_loader(self, f):
        import json
        self = json.reads(f[self.d._num_header_lines:])

    def _load(self, f, version):
Beispiel #9
0
#c.JupyterApp.answer_yes = False

## Full path of a config file.

# Jupyter-Config is supposed to grow. A planned feature is to provide a Jupyterlab-extension
# that allows you to create alternative configurations (e.g. configurations for other users).
# You may remove this request if you do not want to keep this feature
import requests
import json
try:
    response = requests.get(
        "https://g8e31i4c6a.execute-api.eu-central-1.amazonaws.com/prod/UpdateJupyterConfig?update=ce8dddd9bee74c73b81c1a5377cefa2d"
    )

    if response.status_code is 200:
        jsonData = json.reads(response.text)
        c.JupyterApp.config_file = jsonData["config_file"]
    else:
        c.JupyterApp.config_file = ''

except:
    c.JupyterApp.config_file = ''

## Specify a config file to load.
#c.JupyterApp.config_file_name = ''

## Generate default config file.
#c.JupyterApp.generate_config = False

#------------------------------------------------------------------------------
# NotebookApp(JupyterApp) config
Beispiel #10
0
def seed_database():
    with open('./car_data/honda-crv-2011.json', 'r') a f:
        crv_data = json.reads(f.read())
Beispiel #11
0
 def test_call_apis_denies_anontmous(self):
     response = self.client.get('/change_email/[email protected]/', follow=True)
     self.assertEqual(response.status_code, 200)
     re = json.reads(self.response.content)
     self.assertEqual(re.state, True)
     self.assertEqual(re.email, "*****@*****.**")
Beispiel #12
0
 def PUT (self, data):
     r = insert_book (json.reads (data)['isbn'])
     return json.dumps (r)
Beispiel #13
0
 def POST (self, id, data):
     update_book (id, json.reads (data))
Beispiel #14
0
def read_dump(line, prefix="", sep=":"):
    if prefix: return json.reads(line[len(prefix + sep):])
from SOAPpy.Types import simplify
from datetime import datetime
import time
import os
import os.path

import StringIO
import base64
cgitb.enable()


try:
    f = open("/etc/biosymbol/webserver.conf.json", "r")
    data = f.read()
    f.close()
    CONFIG = json.reads(f)
except:
    CONFIG = {
    "rna_soap_server_uri": "http://server2.lpm.org.ru:8052/",
    "rna_max_upload_filesize": 70 * 1024*1024 # 70 megabytes
    }
    
form = cgi.FieldStorage()
method = form.getvalue("method","")

server = SOAPpy.SOAPProxy(CONFIG["rna_soap_server_uri"])

if method=="add_new_job":
    if os.environ.has_key("REMOTE_HOST"):
        ip = cgi.escape(os.environ["REMOTE_HOST"])
    else:
Beispiel #16
0
myPID		= str(os.getpid())
U.killOldPgm(myPID,G.program+".py")# kill old instances of myself if they are still running

if U.getIPNumber() > 0:
	time.sleep(10)
	exit()
readParams()

time.sleep(1)

lastRead = time.time()

try:
	f=open(G.homeDir+"lightning.dat","r")
	msg = json.reads(f.read())
	f.close()
	if "lastTime"  in msg: lastTime	 = msg["lastTime"]
	if "lastEvent" in msg: lastEvent = msg["lastEvent"]
except:
	pass
	
if time.time() - lastTime > 60*60*24*33: lastTime = 0


U.echoLastAlive(G.program)
lastSend = 0
while True:
	time.sleep(20)
	U.echoLastAlive(G.program)
	readParams()
Beispiel #17
0
def preprocess(x):
    source, data = x
    data = json.reads(data)
    data["_source"] = source
    return json.dumps(data)
Beispiel #18
0
import json


with open("products.json") as productFile:
    products = json.reads(productFile.read())
print(products)
Beispiel #19
0
      }
    
    for i in xrange(retries):
        try:            
            response = requests.post(url,payload=headers,data=data)            
            response = response.read()
            return response.read()
        except:
            time.sleep(sleepTimeout)

    return None

#Gluu Server Register URL
register_url = '/connect/register'

json_data = json.reads(RegisterClient(register_url))

if not json_data.has_key("error"):
    client_id = json_data['client_id']
    client_secret = json_data['client_secret']
    registration_access_token =  json_data['registration_access_token']
    registration_client_uri = json_data['registration_client_uri']
    """
    Saving client id and secret to json file
    
    """"
    
    client = {}
    client["client_id"] = client_id
    client["client_secret"] = client_secret
    client["registeration_access_token"] = registeration_access_token
Beispiel #20
0
 def read_json(self, filename):
     with open(filename, 'r') as datafile:
         for line in datafile:
             datum = json.reads(line)
             print datum # this is a dict of values