Esempio n. 1
0
 def _json(self, d):
     json = self.env.session.ui.render_json(d)
     # These are necessary so the browser doesn't get confused by things
     # when JSON is included directly into the HTML as a <script>.
     json = json.replace('<', '\\x3c')
     json = json.replace('&', '\\x26')
     return json
Esempio n. 2
0
 def _json(self, d):
     json = self.env.session.ui.render_json(d)
     # These are necessary so the browser doesn't get confused by things
     # when JSON is included directly into the HTML as a <script>.
     json = json.replace('<', '\\x3c')
     json = json.replace('&', '\\x26')
     return json
Esempio n. 3
0
def GrabElement(json, element):
	json = json.partition(str(element) + '":')[2]
	json = json.partition(',')[0]
	if '"' in str(json):
		json = json.replace('"', '')
	if '{' in str(json):
		json = json.replace('{', '')
	if '}' in str(json):
		json = json.replace('}', '')
	return json
Esempio n. 4
0
def render_and_write_temp_schema(output_filename, template, replace_l):
     """Write a temporary schema file
     
     Renders a temporary schema file from a template. Each element in the 
     replacement list indicates a string to replace in the template file, as
     well as what to replace it with

     Arguments:
         output_filename (str): output file path
         template (str): JSON schema template filename
         replace_l (list): replacement list
     """

     # open the template schema
     schema_dir = os.path.dirname(sv.__file__) \
                     + "/" + c.SCHEMA_RELATIVE_DIR
     template_file = schema_dir + "/" + template
     json = open(template_file, "r").read()

     # for each item in the replacement list, replace the placeholder text
     # in the template, with the true value to be output to the temporary
     # schema
     for replace in replace_l:
          json = json.replace(replace[0], replace[1])

     # write the temporary schema file
     out_path = schema_dir + "/" + output_filename
     open(out_path, "w").write(json)
Esempio n. 5
0
def send_fortune():
    headers = {
        'User-Agent':
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
        'Accept':
        'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
        'Accept-Encoding': 'none',
        'Accept-Language': 'en-US,en;q=0.8',
        'Connection': 'keep-alive'
    }

    print('In send fortune!')

    request = Request('https://helloacm.com/api/fortune/', headers=headers)
    json = urlopen(request).read().decode()

    url = 'https://api.groupme.com/v3/bots/post'

    testcommand = 'curl -d "{\\"text\\" : \\"' + json.replace(
        '\\n', ' ').replace('"', '').replace('\\t', '    ').replace(
            '\\', '"') + '\\", \\"bot_id\\" : \\"' + os.getenv(
                'GROUPME_BOT_ID'
            ) + '\\"}" https://api.groupme.com/v3/bots/post'
    print('command string: ' + testcommand)
    os.system(testcommand)
def convert_dict_to_playjson(json, indentation):
    if isinstance(json, dict):
        print "Json.obj()",
        indentation += 1
        for k, v in json.items():
            print ""
            print "\t" * indentation,
            if v is None:
                sys.stdout.write('.addNull("' + k + '")')
            else:
                sys.stdout.write('.add("' + k + '", ')
                convert_dict_to_playjson(v, indentation)
                sys.stdout.write(")")

        sys.stdout.write(".build()")
        indentation -= 1
    elif isinstance(json, list):
        print 'Json.arr()',
        indentation += 1
        for v in json:
            print ""
            print "\t" * indentation,
            sys.stdout.write('.add(')
            convert_dict_to_playjson(v, indentation)
            sys.stdout.write(")")

        sys.stdout.write(".build()")
        indentation -= 1
    elif isinstance(json, basestring):
        sys.stdout.write('"' + json.replace("\\", "\\\\") + '"')
    else:
        sys.stdout.write(str(json))
    return
Esempio n. 7
0
 def setVars(self, json, params=()):
     """Set javascript variables names as values 
     to a json object"""
     if isinstance(params,(str)):
         params = (params)
     json = json.replace('"%s"','%s')
     return json % params
Esempio n. 8
0
def parse(json):
    json = json.replace(');', '')
    json = json.replace('google.visualization.Query.setResponse(', '')
    json = json.replace('new Date', 'Date')
    #stuff = stuff.replace(', ', ',\n')
    stuff = eval(
        json, {
            'status': 'status',
            'Date': javascriptDate,
            'null': None,
            'table': 'table',
            'false': False
        })
    p = stuff['table']['p']
    html = p['html_content3']
    if len(html) == 0:
        html = p['html_content4'] + p['html_content5']
    parser = MyHTMLParser()
    parser.feed(html)
    if len(parser.data) == 0:
        return None, None
    conditionText = parser.data[-1]
    if conditionText[0] == ':':
        conditionText = None
    elif conditionText in ignore:
        conditionText = None
    elif conditionText not in conditions:
        print(repr(conditionText))
        print(repr(stuff))
        print()
        exit(1)
    i = parser.data.index('Last Observation')
    lastObservation = parser.data[i + 1]
    if (lastObservation[0] != ':'):
        print(lastObservation)
        pprint.PrettyPrinter().pprint(stuff)
        return None, None
    timezonestr = lastObservation.split()[-1]
    lastObservation = datetime.datetime.strptime(lastObservation,
                                                 ': %A, %B %d %Y %H:%M %Z')
    if timezonestr == 'EST':
        utctime = lastObservation + datetime.timedelta(hours=5)
    else:
        utctime = lastObservation + datetime.timedelta(hours=4)
    utctime = utctime.replace(tzinfo=datetime.timezone.utc)
    return utctime, conditionText
Esempio n. 9
0
def _parse_message_to_json(message):
    """Parses a gRPC request object to a JSON string.

    Args:
        request: an instance of the SearchGoogleAdsRequest type
    """
    json = MessageToJson(message)
    json = json.replace(', \n', ',\n')
    return json
Esempio n. 10
0
def _parse_message_to_json(message):
    """Parses a gRPC request object to a JSON string.

    Args:
        request: an instance of a request proto message, for example
            a SearchGoogleAdsRequest or a MutateAdGroupAdsRequest.
    """
    json = MessageToJson(message)
    json = json.replace(', \n', ',\n')
    return json
Esempio n. 11
0
 def replace_variable(self, json, variable, text):
     if isinstance(json, dict):
         return {self.replace_variable(k, variable, text):
                 self.replace_variable(v, variable, text) for k, v in json.items()}
     elif isinstance(json, list):
         return [self.replace_variable(i, variable, text) for i in json]
     elif isinstance(json, str):
         return json.replace('${' + variable + '}', text)
     else:
         return json
Esempio n. 12
0
 def replace_variable(self, json, variable, text):
     if isinstance(json, dict):
         return {k:
                 self.replace_variable(v, variable, text) for k, v in json.items()}
     elif isinstance(json, list):
         return [self.replace_variable(i, variable, text) for i in json]
     elif isinstance(json, str):
         return json.replace('${' + variable + '}', text)
     else:
         return json
Esempio n. 13
0
def get_loaded_segments(data_source):
    path = os.path.join(my_path, "loaded_segments.json")
    with open(path) as input_file:
        import json
        loaded_segments = json.load(input_file)
        segment_ids = set()
        for json in loaded_segments:
            json = json.replace('/', '_')
            json = data_source + "_" + json
            segment_ids.add(str(json))
        return segment_ids
Esempio n. 14
0
 def dataset_json(self):
     jsons = []
     for dataset in self.datasets:
         json = dataset.to_json(
             double_precision=self.double_precision,
             orient="split",
             force_ascii=False,
         )
         json = json.replace('"columns":', '"dimensions":').replace(
             '"data":', '"source":')
         jsons.append(json)
     return ",".join(jsons)
Esempio n. 15
0
def getCreateDocumentJson(documentName, mimetype):
    replacements = {
        "titel": documentName,
        "beskrivelse": "MoxDocumentUpload",
        "mimetype": mimetype,
        "brugervendtnoegle": "brugervendtnoegle",
        "virkning.from": datetime.datetime.now().isoformat()
    }
    json = CREATE_DOCUMENT_JSON
    for key, value in replacements.items():
        json = json.replace("${%s}" % key, value)
    return json
Esempio n. 16
0
 def replace_variable(self, json: Json, variable: str, text: str) -> Json:
     if isinstance(json, dict):
         return {
             self.replace_variable(k, variable, text):
             self.replace_variable(v, variable, text)
             for k, v in json.items()
         }
     elif isinstance(json, list):
         return [self.replace_variable(i, variable, text) for i in json]
     elif isinstance(json, str):
         return json.replace("${" + variable + "}", text)
     else:
         return json
Esempio n. 17
0
def json2det(json_path, det1_path):
    fdet = open(det1_path + '/det.txt', 'w')
    for json in glob.glob(json_path + '/*.json'):
        json_anno = ReadAnno(json, process_mode="polygon")
        img_width, img_height = json_anno.get_width_height()
        filename = os.path.basename(json.replace(".json", ".jpg"))
        frame = int(filename[5:8])
        coordis = json_anno.get_coordis()
        for xmin, ymin, xmax, ymax, label in coordis:
            label_str = '{:d},-1,{:.2f},{:.2f},{:.2f},{:.2f},1,-1,-1,-1\n'.format(
                frame, xmin, ymin, xmax - xmin, ymax - ymin)
            fdet.write(label_str)
    fdet.close()
    def to_jsonp(self, data, options=None):
        """
        Given some Python data, produces JSON output wrapped in the provided
        callback.

        Due to a difference between JSON and Javascript, two
        newline characters, \u2028 and \u2029, need to be escaped.
        See http://timelessrepo.com/json-isnt-a-javascript-subset for
        details.
        """
        options = options or {}
        json = self.to_json(data, options)
        json = json.replace(u'\u2028', u'\\u2028').replace(u'\u2029', u'\\u2029')
        return u'%s(%s)' % (options['callback'], json)
Esempio n. 19
0
def blockinfo(IP):
        ###Needs to be simplified with JSON
        import urllib,urllib2,json,re
        test = re.search("(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",IP)
        if test == None:#user
            passdict = {"action":"query", "list":"blocks", "bkprop":"id|user|by|timestamp|expiry|reason|range|flags", "bklimit":"1","bkusers":IP}
        else:#ip
            passdict = {"action":"query", "list":"blocks", "bkprop":"id|user|by|timestamp|expiry|reason|range|flags", "bklimit":"1","bkip":IP}
        urldata = urllib.urlencode(passdict)
        baseurl = "http://en.wikipedia.org/w/api.php"
        url = str(baseurl) + "?" + str(urldata)
        urlobj = urllib2.urlopen(url)
        json = urlobj.read()
        urlobj.close()
        try:json = json.split("<span style=\"color:blue;\">&lt;blocks&gt;</span>")[1]
        except:return "User is not blocked."
        json = json.split("<span style=\"color:blue;\">&lt;/blocks&gt;</span>")[0]
        json = json.split("<span style=\"color:blue;\">&lt;")[1]
        json = json.replace("&quot;","\"")
        bid=json.split("block id=\"")[1]
        bid=bid.split("\"")[0]
        gen="Block " + str(bid)
        bid=json.split("user=\"")[1]
        bid=bid.split("\"")[0]
        gen=gen+" targeting " + str(bid)
        bid=json.split("by=\"")[1]
        bid=bid.split("\"")[0]
        gen=gen+" was blocked by " + str(bid)
        bid=json.split("timestamp=\"")[1]
        bid=bid.split("\"")[0]
        gen=gen+" @" + str(bid)
        bid=json.split("expiry=\"")[1]
        bid=bid.split("\"")[0]
        gen=gen+" and expires at " + str(bid)
        bid=json.split("reason=\"")[1]
        bid=bid.split("\"")[0]
        gen=gen+" because \"" + str(bid) + "\" ("
        gen = gen.replace("&amp;lt;","<")
        gen = gen.replace("&amp;gt;",">")
        if "nocreate" in json:
            gen = gen + "Account Creation Blocked, "
        if "anononly" in json:
            gen = gen + "Anonomous Users Only, "
        else:
            gen = gen + "Hardblocked, "
        if not "allowusertalk" in json:
            gen = gen + "User Talk Page REVOKED)"
        else:
            gen = gen + "User Talk Page allowed)"
        return gen
Esempio n. 20
0
    def to_jsonp(self, data, options=None):
        """
        Given some Python data, produces JSON output wrapped in the provided
        callback.

        Due to a difference between JSON and Javascript, two
        newline characters, \u2028 and \u2029, need to be escaped.
        See http://timelessrepo.com/json-isnt-a-javascript-subset for
        details.
        """
        options = options or {}
        json = self.to_json(data, options)
        json = json.replace(u'\u2028', u'\\u2028').replace(u'\u2029', u'\\u2029')
        return u'%s(%s)' % (options['callback'], json)
Esempio n. 21
0
def convert_pascal_to_tfrecord():
    json_path = FLAGS.data_dir + FLAGS.json_dir
    image_path = FLAGS.data_dir + FLAGS.image_dir
    save_path = FLAGS.save_dir + cfgs.VERSION + '_' +  FLAGS.dataset + '_' + FLAGS.save_name + '.tfrecord'
    print(save_path)
    mkdir(FLAGS.save_dir)
    # writer_options = tf.python_io.TFRecordOptions(tf.python_io.TFRecordCompressionType.ZLIB)
    # writer = tf.python_io.TFRecordWriter(path=save_path, options=writer_options)
    writer = tf.python_io.TFRecordWriter(path=save_path)
    # print(json_path)
    for count, json in enumerate(glob.glob(json_path + '/*.json')):
        print(json)
        # to avoid path error in different development platform
        json = json.replace('\\', '/')

        img_name = json.split('/')[-1].split('.')[0] + FLAGS.img_format
        img_path = image_path + '/' + img_name

        if not os.path.exists(img_path):
            print('{} is not exist!'.format(img_path))
            continue
        # read_json_gtbox_and_label(json)
        img_height, img_width, gtbox_label = read_json_gtbox_and_label(json)
        print('gtbox shape' ,gtbox_label.shape)
        print('gtbox ' ,gtbox_label)
        if gtbox_label.shape[0] == 0:
            continue
        # img = np.array(Image.open(img_path))
        img = cv2.imread(img_path)

        feature = tf.train.Features(feature={
            # do not need encode() in linux
            'img_name': _bytes_feature(img_name.encode()),
            # 'img_name': _bytes_feature(img_name),
            'img_height': _int64_feature(img_height),
            'img_width': _int64_feature(img_width),
            'img': _bytes_feature(img.tostring()),
            'gtboxes_and_label': _bytes_feature(gtbox_label.tostring()),
            'num_objects': _int64_feature(gtbox_label.shape[0])
        })

        example = tf.train.Example(features=feature)

        writer.write(example.SerializeToString())

        view_bar('Conversion progress', count + 1, len(glob.glob(json_path + '/*.json')))
    
    # print(label_list)
    
    print('\nConversion is complete!')
Esempio n. 22
0
	def sql_save(self, sql):
		Event.sql_create(sql)
		
		if self.signal_id == None:
			raise Exception("Missing signal id to store event: %s" % str(self.to_json()))
		
		if self.type == None:
			raise Exception("Missing event type to store event %s: %s" % str(self.to_json()))
		
		# Prepare json data string
		json = str(self.to_json())
		json = json.replace("u'","'")
		json = json.replace("'","\"")
		
		if self.id == None:
			sql.execute("INSERT INTO events (signal_id, type, json) "
						"VALUES (?, ?, ?)", (self.signal_id, self.type, json))
			self.id = sql.lastrowid
			log.debug("Created event id %s for signal id %s" % (self.id, self.signal_id))
		else:
			sql.execute("UPDATE events "
						"SET signal_id = ?, type = ?, json = ? "
						"WHERE id = ?", (self.signal_id, self.type, json, self.id))
			log.debug("Updated event id %s for signal id %s" % (self.id, self.signal_id))
Esempio n. 23
0
 def data_replacement_json(file_name, dataset):
     """
     Method uses Jinja Templates to replace a set of values in provided JSON file and returns replaced JSON
     :param file_name:
     :param dataset:
     :return json:
     """
     template_file = read_file(file_name)
     template_file = template_file.replace('\\', 'BACKSLASH').replace(
         '{{', 'OPEN_BRACKET').replace('}}', 'CLOSE_BRACKET')
     template_file = template_file.replace('{_{', '{{').replace('}_}', '}}')
     template = Template(template_file)
     json = template.render(dataset)
     json = json.replace('BACKSLASH',
                         '\\').replace('OPEN_BRACKET',
                                       '{{').replace('CLOSE_BRACKET', '}}')
     return json
Esempio n. 24
0
def json_transform_txt(json_path, txt_path, process_mode="rectangle"):
    json_path = json_path
    json_anno = ReadAnno(json_path, process_mode=process_mode)
    img_width, img_height = json_anno.get_width_height()
    #filename = json_anno.get_filename()
    filename = os.path.basename(json.replace(".json", ".jpg"))
    coordis = json_anno.get_coordis()
    save_path = os.path.join(txt_path, filename.replace(".jpg", ".txt"))
    with open(save_path, mode='w') as fp:
        for xmin, ymin, xmax, ymax, label in coordis:
            # top_x,top_y,down x,down y---->cen_x,cen_y,width,height
            x = round((xmin + (xmax - xmin) / 2) / img_width, 6)
            y = round((ymin + (ymax - ymin) / 2) / img_height, 6)
            width = round((xmax - xmin) / img_width, 6)
            height = round((ymax - ymin) / img_height, 6)
            label_str = '{:s} {:f} {:f} {:f} {:f}\n'.format(
                label, x, y, width, height)
            fp.write(label_str)
Esempio n. 25
0
 def execute(self,json):
     rlue = self.rlue
     print json
     # try:
     for n in range(len(json.loads(json)["data"])):
         Ignorebit == ""
         for m in range(len(rlue["p"]["where"])):
             Ignorebit = Where.select(rlue,json,n,m)
             if Ignorebit == "0":
                 break
         if Ignorebit == "1":
             for o in range(len(rlue["p"]["ignore"])):
                 ignorekey = rlue["p"]["ignore"].keys()[o]
                 ignorevlue = rlue["p"]["ignore"][o][ignorekey]
                 replacevlue = json.loads(json)["data"][n].pop(ignorekey)
                 json = json.replace(replacevlue,ignorevlue)
         else:
             pass
     # except Exception:
     #     print Exception,"IgnoreVlueRule"
     return json
Esempio n. 26
0
def handleJson(json,  yybcode, filecsv):
	#print urlcode
	#json=urlcode[0]
	txt=json.replace('\n','')
	txt=txt.replace('\'','')
	re_str='data:\[\[(.*)\]\]\};'
	re_pat = re.compile(re_str)
	search_ret = re_pat.search(txt)
	ele=search_ret.groups()[0]
	se =  ele.split('],[')
	#print se
	
	buytimes = 0
	selltimes = 0 
	buytotal = 0
	selltotal= 0
	for node  in se:
		print >> filecsv, node, yybcode
		print node.decode('utf-8').encode('gbk')
		#获得每天的交易具体信息,并分列
		line = node.split(',')
		if float(line[2]) > 0:
			buytimes += 1
			buytotal += float(line[2])
		if float(line[3]) > 0:
			selltimes += 1
			selltotal += float(line[3])
	#净利润
	netrate = selltotal - buytotal;
	#操作交易额
	optotal=selltotal + buytotal
	#操作成功利润率
	opsuccess=netrate/optotal;
	print yybcode, " 买入次数:", buytimes, " 买入总额:", buytotal, " 卖出次数:", selltimes,  " 卖出总额:", selltotal, " 净利润:", netrate, " 操作成功利润率:", opsuccess
	print  "--------------------------------"+basicData.getYYBDataByCode(yybcode)+"--------------------------------------"
	line =se[0].split(',')
	#print "line : ", line
	
	return se
    def get_page_json(self, server, restaurant_link):
        url_de = 'https://www.tripadvisor.de'
        request = server.get(restaurant_link)
        server_response_in_html = bs(request.content, 'lxml')

        script_tags = server_response_in_html.body.find_all('script')

        for script_tag in script_tags:

            if len(script_tag.contents) == 0:
                print("----------------")
            elif len(script_tag.contents) > 0:
                text = script_tag.contents[0]
                if 'window.__WEB_CONTEXT__'.lower() in text.lower():
                    json = text.replace('window.__WEB_CONTEXT__={pageManifest', '{"pageManifest"')
                    cut_string = ";(this.$WP=this.$WP||[]).push(['@ta/features',function(e){return [function(){e('default',__WEB_CONTEXT__.pageManifest.features);},[]]},[]]);"
                    json = json.replace(cut_string, '')
                    cities = server_response_in_html.find_all('link', href=True)
                    for city in cities:
                        link = city['href']
                        x = link.find(url_de)
                        if x == 0:
                            return json, link
Esempio n. 28
0
def process_heatmap(item, params):
    data = item["data"]
    item["height"] = len(data)
    item["width"] = len(data[0])
    # FIXME : temp hack
    #item["width"] = min(item["width"], 400)
    #item["height"] = 0
    if not "min" in item:
        item["min"] = min([min(k) for k in data])
    if not "max" in item:
        item["max"] = max([max(k) for k in data])
    colormap = item["colormap"] if "colormap" in item else DEFAULT_COLORMAP
    if type(colormap) in (str, unicode):
        if colormap in COLORMAPS: colormap = COLORMAPS[colormap]
        else: colormap = DEFAULT_COLORMAP
    img = colorize_heatmap(data, item["min"], item["max"], colormap)
    heatmap_json = "%08d.json" % process_heatmap.heatmap_id
    process_heatmap.heatmap_id += 1
    # Save image
    imgpath = os.path.join(params["target_dir"], "imgs", "json")
    if not os.path.exists(imgpath): os.makedirs(imgpath)
    img.save(os.path.join(imgpath, heatmap_json + ".png"), "PNG")
    item["imgurl"] = os.path.join("imgs", "json", heatmap_json + ".png")
    # Save JSON
    jsonpath = os.path.join(params["target_dir"], "json")
    if not os.path.exists(jsonpath): os.makedirs(jsonpath)
    json_data = json.dumps(data)
    json_data = json_data.replace(" ", "")
    open(os.path.join(jsonpath, heatmap_json), "w").write(json_data)
    gzip.open(os.path.join(jsonpath, heatmap_json + ".gz"), "w").write(json.replace(" ", ""))
    del item["data"]
    # FIXME: dirty hack for gzipped jsons
    if params["WEB_ROOT"] in params["target_dir"]:
        item["url"] = os.path.join("static", "php", "servejson.php?json=" + heatmap_json)
    else:
        item["url"] = os.path.join("json", heatmap_json)
    return item
Esempio n. 29
0
    def LocalJsonHandler(self, handler, is_2d=False, json_version=1):
        """Handle GET request for JSON file for plugin."""
        if not handler.IsValidRequest():
            raise tornado.web.HTTPError(404)

        current_globe = ""
        globe_request_name = self.ParseGlobeReqName(handler.request.uri)
        if globe_request_name != -1 and globe_request_name != 1:
            # Requested globe name is valid, so select it
            current_globe = tornado.web.globe_.GlobeName()
            globe_path = "%s%s%s" % (tornado.web.globe_.GlobeBaseDirectory(),
                                     os.sep, globe_request_name)
            tornado.web.globe_.ServeGlobe(globe_path)

        # Get to end of serverUrl so we can add globe name.
        # This will fail if serverDefs are requested for a glc file
        try:
            if is_2d:
                # TODO: Add real layer support for mbtiles.
                if tornado.web.globe_.IsMbtiles():
                    json = MBTILES_JSON
                else:
                    # Portable seems to believe that 2D files are 3D when they
                    # are not actively being viewed by a client, so handle
                    # both possibilities in either case.
                    try:
                        json = tornado.web.globe_.ReadFile("maps/map.json")
                    except:
                        json = tornado.web.globe_.ReadFile("earth/earth.json")
            else:
                try:
                    json = tornado.web.globe_.ReadFile("earth/earth.json")
                except:
                    json = tornado.web.globe_.ReadFile("maps/map.json")

        except:
            handler.write("var geeServerDefs = {};")
            return

        host = handler.request.host
        json = json.replace("localhost:9335", host)
        json = json.replace(" : ", ": ")

        WHITE_SPACE_ALLOWED = 3
        index0 = json.find("serverUrl")
        if index0 == -1:
            print "Non-standard 2d map json."
            handler.write(json)
            return
        else:
            index0 += 9

        index1 = json.find(":", index0)
        if index1 == -1 or index1 > index0 + WHITE_SPACE_ALLOWED:
            print "Non-standard 2d map json."
            handler.write(json)
            return
        else:
            index1 += 1

        index2 = json.find('"', index1)
        if index2 == -1 or index2 > index1 + WHITE_SPACE_ALLOWED:
            print "Non-standard 2d map json."
            handler.write(json)
            return
        else:
            index2 += 1

        index3 = json.find('"', index2)
        if index3 == -1:
            print "Non-standard 2d map json."
            handler.write(json)
            return

        json_start = json[:index3].strip()
        json_end = json[index3:]

        # Get rid of the end of structure, so we can add to it.
        json_end = json_end[:json_end.rfind("}")].strip()

        # If not from a remote server, show available globes.
        if handler.IsLocalhost():
            # Add information about available globes
            json_end = (("%s,\n\"selectedGlobe\": \"%s\"\n, "
                         "\"globes\": [\"%%s\"]};") %
                        (json_end, tornado.web.globe_.GlobeName()))
            json_end %= "\", \"".join(
                portable_web_interface.SetUpHandler.GlobeNameList(
                    tornado.web.globe_.GlobeBaseDirectory(),
                    [".glc", ".glb", ".glm"]))
        else:
            json_end += "};"

        # Adding globe name helps ensure clearing of cache for new globes.
        json_text = "%s/%s%s" % (json_start,
                                 tornado.web.globe_.GlobeShortName(), json_end)

        if json_version == 2:
            json_text = self.JStoJson(json_text)

        handler.write(json_text)

        # If we switched globes, switch back
        if len(current_globe):
            globe_path = "%s%s%s" % (tornado.web.globe_.GlobeBaseDirectory(),
                                     os.sep, globe_request_name)
            tornado.web.globe_.ServeGlobe(globe_path)
Esempio n. 30
0
def portal_tree_json_view(request):
    nodes = request.portal.root.get_descendants(include_self=True)
    json = render_to_string('portals/portal-tree.json', {'nodes': nodes})
    json = json.replace('}{', '},{')
    return HttpResponse(json)
Esempio n. 31
0
def test_handling_valid_geojson_empty_geometries():
    for json in valid_empty_geometries:
        geom = mapnik.Geometry.from_geojson(json)
        out_json = geom.to_geojson()
        # check round trip
        eq_(json.replace(" ",""), out_json)
Esempio n. 32
0
File: forum.py Progetto: mimir/mimir
 def toJSON(self):
     json = r'{"pk":%d, "lesson":"%s", "question":"%s", "answer":"%s", "user_tag":"%s", "title":"%s", "content":"%s", "created":%d, "modified":%d, "rating":%d}' % (self.pk, self.lesson, self.question, self.answer, self.user_tag, self.title, self.content, self.created, self.modified, self.rating)
     json = json.replace('\\', '\\\\').replace("\n", r"<\br>").replace("\r", r"")
     return json
def test_handling_valid_geojson_empty_geometries():
    for json in valid_empty_geometries:
        geom = mapnik.Geometry.from_geojson(json)
        out_json = geom.to_geojson()
        # check round trip
        eq_(json.replace(" ", ""), out_json)
Esempio n. 34
0
    if dsname not in files_dict.keys():
      nent_dict[dsname] = 0
      files_dict[dsname] = []
    with open(fnm) as f: 
      for line in f:
        if ("nEventsTotal" in line): # this is read instead of calculated to make resubmission simpler
          nent_dict[dsname] = nent_dict[dsname] + int(line.split().pop())
        if "/store" not in line: continue
        col = line.split()
        files_dict[dsname].append(col[2])

# form new datasets from the data split into subperiods
for pd in data_wishlist:
  # book the dataset names for all sub-periods in advance
  for json in jsonlist:
    dsname = pd + json.replace('data/json/subgolden','').replace('.json','')
    files_dict[dsname] = []
    nent_dict[dsname] = 0 # not filled for data
  # read flists
  flists_pd = glob.glob(os.path.join(flistdir,"flist_"+pd+"_Run2015D*.txt"))
  for fnm in flists_pd:
    with open(fnm) as f: 
      for line in f:
        if "/store" not in line: continue
        col = line.split()
        runlist = [int(irun) for irun in string.split(col[3],",")]
        for run in runlist:
          for jsonfile in goldruns.keys():
            if run in goldruns[jsonfile]:
              dsname = pd + jsonfile.replace('data/json/subgolden','').replace('.json','')
              if (col[2] not in files_dict[dsname]): # don't add same file twice if it has two runs in this subperiod
def sanitize_json(json):
    json = json.replace("\'", "\"")
    json = json.split('[')[1].split(']')[0]
    json = json[0:len(json) - 6] + "}"
    return json
Esempio n. 36
0
def _json_formatting(json):
	json = json[7:]
	json= json.replace("'", '"')
	return json
Esempio n. 37
0
def parseJSON(json):
    json=json.replace("[,","[None,")
    json=json.replace(",,",",None,")
    json=json.replace(",,",",None,")
    json=json.replace(",]",",None]")
    return eval("#"+json)
Esempio n. 38
0
def api_call(service = None, meta = None, query = None):
    #ipdb.set_trace()
    if service is None:
        service = request.args.get('service')
    if meta is None:
        meta = request.args.get('meta')
    if query is None:
        query = request.args.get('q')

    print "Service: ",service
    print "Meta/Method: ",meta
    print "Query: ",query

    if service == [''] or service is None:
        response.status = 400
        return 'No service selected'
    elif len(service) == 1:
        json = '''{"results": "result"}'''

    # MongoDB (nSides)
    elif service == 'nsides':
        # e.g. /api/v1/query?service=nsides&meta=estimateForDrug_Outcome&drugs=19097016&outcome=4294679&model=nopsm
        if meta == 'estimateForDrug_Outcome':
            #drugs = [drug.replace('|',',') for drug in request.params.get('drugs').split(',')]
            # ^ Separate individual drugs using comma. Drug class represented as `DrugA|DrugB|etc`
            drugs = request.args.get('drugs')
            all_drugs_ingredients = convertDrugsToIngredients(drugs)
            if drugs == [''] or drugs is None:
                response.status = 400
                return 'No drug(s) selected'

            outcome = request.args.get('outcome')
            if outcome == [''] or outcome is None:
                response.status = 400
                return 'No outcome selected'

            model_type = request.args.get('model')
            if model_type == [''] or model_type is None:
                model_type = 'all'

            query = {'drugs': all_drugs_ingredients, 'outcome': outcome, 'model': model_type}
            # print "Parsed query:", query

            service_result = query_nsides_mongo.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))

        # e.g. /api/v1/query?service=nsides&meta=topOutcomesForDrug&numResults=10&drugs=19097016

    elif service == 'druginfo':
        # e.g. /api/v1/query?service=druginfo&meta=jobIndexes&drugs=19097016
        if meta == 'jobIndexes':
            drugs = request.args.get('drugs')
            if drugs == [''] or drugs is None:
                response.status = 400
                return 'No drug(s) selected'
            query = {'drugs': drugs}
            service_result = query_nsides_mongo.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
        
    elif service == 'gpcr':
        if meta == 'gpcrFromUniprot':
            uniprot_id = request.args.get('uniprot')
            if uniprot_id == [''] or uniprot_id is None:
                response.status = 400
                return 'No Uniprot ID provided'
            query = {'uniprot': uniprot_id}
            service_result = query_nsides_mongo.query_db(service, meta, query)
            #json = service_result
            json = '''{"results": %s}''' %(str(service_result))

    # MySQL
    elif service == 'lab':
        if meta == 'ae_to_lab':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
    elif service == 'omop':
        if meta == 'reference':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'conceptsToName':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
    elif service == 'sider':
        if meta == 'drugForEffect':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'drugForEffectFreq':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'search_term':
            json = '''{"results": [c1, c2, c3 ... cn]} CONCEPT_ID'''
    elif service == 'va':
        if meta == 'get_ddi_alerts':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
    elif service == 'snomed':
        if meta == 'getOutcomeFromSnomedId':
            service_result = query_nsides_mysql.query_db(service, meta, query)
            json = '''{"results": %s}''' %(str(service_result))
    elif service == 'aeolus':
        if meta == 'ingredientList':
            service_result = query_nsides_mysql.query_db(service, meta)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'drugReactionCounts':
            service_result_1 = query_nsides_mysql.query_db(service, meta, query)
            #service_result_2 = query_nsides_mysql.query_db(service, meta)
            #json = '''{"results": %s, "nrows": %s}, ''' %(str(service_result_1), str(service_result_2))
            json = '''%s''' %(str(service_result_1))
        elif meta == 'drugpairReactionCounts':
            #service_result = query_nsides_mysql.query_db(service, meta, query)
            #json = '''{"results": %s}''' %(str(service_result))
            service_result_1 = query_nsides_mysql.query_db(service, meta, query)
            json = '''%s''' %(str(service_result_1))
        elif meta == 'reactionListSNOMED':
            service_result = query_nsides_mysql.query_db(service, meta)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'reactionListMedDRA':
            service_result = query_nsides_mysql.query_db(service, meta)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'drugpairList':
            service_result = query_nsides_mysql.query_db(service, meta)
            json = '''{"results": %s}''' %(str(service_result))
        elif meta == 'drugpairReactionListMedDRA':
            service_result  = query_nsides_mysql.query_db(service, meta)
            json = '''{"results": %s}''' %(str(service_result))
    else:
        json = '''{"": ""}'''

    json = json.replace("'", '"')
    print 'Completing requests with ', json[0:14]
    return json
Esempio n. 39
0
 def fix_json(self, json):
     """remove slashes since they can break download process"""
     json = json.replace('\'', '"')
     sep_index = json.find('<!>')
     json = json[:sep_index]
     return json
Esempio n. 40
0
def portal_tree_json_view(request):
    nodes = request.portal.root.get_descendants(include_self=True)
    json = render_to_string('portals/portal-tree.json', {'nodes': nodes},
                            request=request)
    json = json.replace('}{', '},{')
    return HttpResponse(json)
Esempio n. 41
0
def clean_json(json):
    json = json.replace('\n', ' ')
    return json.replace(r'\\', 'M@THJ@X')
Esempio n. 42
0
File: forum.py Progetto: mimir/mimir
 def toJSON(self):
     json = r'{"user_tag":"%s", "content":"%s", "created":%d, "modified":%d, "rating":%d}' % (self.user_tag,  self.content, self.created, self.modified, self.rating)
     json = json.replace('\\', '\\\\').replace("\n", r"\n").replace("\r", r"\r")
     return json
def pythonizeJson(json):
    json = json.replace("\r", "")
    json = json.replace("true", "True")
    json = json.replace("false", "False")
    json = json.replace("null", "None")
    return eval(json, {}, {})
Esempio n. 44
0
        'PERFETTO_TEST_SCRIPT': 'test/ci/ui_tests.sh',
    },
    'ui-clang-x86_64-release': {
        'PERFETTO_TEST_GN_ARGS': 'is_debug=false',
        'PERFETTO_TEST_SCRIPT': 'test/ci/ui_tests.sh',
    },
}

if __name__ == '__main__':
  import os
  import json
  import re
  import sys
  vars = dict(kv for kv in locals().items() if re.match('^[A-Z0-9_]+$', kv[0]))

  if len(sys.argv) > 1 and sys.argv[1] == 'makefile':
    gen_file = os.path.join(os.path.dirname(__file__), '.deps', 'config.mk')
    with open(gen_file, 'w') as f:
      for k, v in vars.iteritems():
        if isinstance(v, (int, long, basestring)):
          f.write('%s=%s\n' % (k, v))
        elif isinstance(v, list):
          f.write('%s=%s\n' % (k, ','.join(v)))
    print gen_file

  if len(sys.argv) > 1 and sys.argv[1] == 'js':
    json = json.dumps(vars, indent=2)
    print '// Auto-generated by %s, do not edit.\n' % __file__
    print '\'use strict\';\n'
    print 'const cfg = JSON.parse(`%s`);\n' % json.replace(r'\"', r'\\\"')
Esempio n. 45
0
def format_json(json):
    return json.replace('""{','{').replace('}""','}').replace('""','"')
Esempio n. 46
0
def fixJson(json: str) -> str:
    fixJson = json.replace('{{', '{"header":{')
    fixJson = fixJson.replace('SELL', '"SELL"')
    fixJson = fixJson.replace('BUY', '"BUY"')
    fixJson = fixJson.replace('"flags_":"{"', '"flags_":{"')
    return fixJson
Esempio n. 47
0
def message_to_json(message):
    json = json_format.MessageToJson(message)
    return re.sub(r' +', ' ', json.replace('\n', ''))
Esempio n. 48
0
def escape_json(json):
	return json.replace('\\', '\\\\'). \
				replace('/', '\\/'). \
				replace('\'', '\\\'')