How to use the simplejson.load function in simplejson

To help you get started, we’ve selected a few simplejson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ucbvislab / p2fa-vislab / detect_breaths.py View on Github external
def alignment_with_breaths(speech_file, alignment_file, out_alignment_file=None):
    pause_idx = 0
    subprocess.call('rm tmpaudio/*.wav', shell=True)

    with open(alignment_file, 'r') as af:
        alignment = json.load(af)["words"]

    new_alignment = []
    for x in alignment:
        if x["alignedWord"] == "sp":
            comp = Composition(channels=1)
            speech = Speech(speech_file, "p")
            comp.add_track(speech)
            start = x["start"]
            end = x["end"]
            # ignore super-short pauses
            if end - start <= .05:
                new_alignment.append(x)
                pause_idx += 1
                continue
            # print "pause", pause_idx-1, "start:", start, "end", end
            # print "len", end - start
github legalosLOTR / mdb / MDB / DBbuilder.py View on Github external
def get_imdb_data(moviename):
    #handle proxy
    if (config.config['http_proxy'] != 'None' and\
            len(config.config['http_proxy']) > 0):
        os.environ['http_proxy'] = config.config['http_proxy']

    if (moviename == ' ' or moviename == ''):
        return None

    try:
        res = json.load(urllib2.urlopen(config.api_url +
            urllib2.quote(moviename) + config.api_extra_opts))
    except urllib2.URLError, e:
        return None

    if (res['Response'] == 'True'):
        return res
    else:
        return None
github SemanticMediaWiki / SemanticResultFormats / formats / Exhibit / exhibit / extensions / curate / files / admin / exhibit.py View on Github external
def load_json(filename):
    if os.path.exists(filename):
        json = simplejson.load(open(filename))
        return json
github Koutoulakis / Deep-Learning-for-Human-Activity-Recognition / Datareader / datareader.py View on Github external
def readSphereFiles(self, filelist, cols, labelToId,idToLabel):
        data = []
        labels = []

        mapping = {'a_ascend': 0, 'a_descend': 1, 'a_jump': 2, 'a_loadwalk': 3, 'a_walk': 4, 'p_bent': 5, 'p_kneel': 6, 'p_lie': 7, 'p_sit': 8,
             'p_squat': 9, 'p_stand': 10, 't_bend': 11, 't_kneel_stand': 12, 't_lie_sit': 13, 't_sit_lie': 14, 't_sit_stand': 15, 't_stand_kneel': 16, 
             't_stand_sit': 17,'t_straighten': 18, 't_turn': 19}

        # mapping2 = {0:'a_ascend',  1:'a_descend',  2:'a_jump',  3:'a_loadwalk',  4:'a_walk',  5:'p_bent',  6:'p_kneel',  7:'p_lie',  8:'p_sit',
        #       9:'p_squat',  10:'p_stand',  11:'t_bend',  12:'t_kneel_stand',  13:'t_lie_sit',  14:'t_sit_lie',  15:'t_sit_stand',  16:'t_stand_kneel', 
        #       17:'t_stand_sit', 18:'t_straighten', 19: 't_turn'}
        for i, filename in enumerate(filelist):
            path = './train/%s/'%filename
            meta_root = './metadata/'
            video_cols = json.load(open(os.path.join(meta_root, 'video_feature_names.json')))
            centre_2d = video_cols['centre_2d']
            bb_2d = video_cols['bb_2d']
            centre_3d = video_cols['centre_3d']
            bb_3d = video_cols['bb_3d']
            print('Reading file %d of %d'%(i+1,len(filelist)))
            meta = json.load(open(os.path.join(path, 'meta.json')))
            acceleration_keys = json.load(open(os.path.join(meta_root, 'accelerometer_axes.json')))
            rssi_keys = json.load(open(os.path.join(meta_root, 'access_point_names.json')))
            video_names = json.load(open(os.path.join(meta_root, 'video_locations.json')))
            pir_names = json.load(open(os.path.join(meta_root, 'pir_locations.json')))
            location_targets = json.load(open(os.path.join(meta_root, 'rooms.json')))
            activity_targets = json.load(open(os.path.join(meta_root, 'annotations.json')))
            
            accel = load_wearable(path,acceleration_keys,rssi_keys)
            vid = load_video(path,video_names)
            pir = load_environmental(path)
github foobnix / foobnix / src / foobnix / online / google / translate.py View on Github external
def translate(text, src='en', to='ru'):    
    '''
    A Python Wrapper for Google AJAX Language API:
    * Uses Google Language Detection, in cases source language is not provided with the source text
    * Splits up text if it's longer then 4500 characters, as a limit put up by the API
    '''

    params = ({'langpair': '%s|%s' % (src, to),
             'v': '1.0'
             })
    retText = ''
    for text in getSplits(text):
            params['q'] = text
            resp = simplejson.load(urllib.urlopen('%s' % (baseUrl), data=urllib.urlencode(params)))
            try:
                    retText += resp['responseData']['translatedText']
            except:
                    raise
    return retText
github mollyproject / mollyproject / trunk / mobile_portal / mobile_portal / maps / search.py View on Github external
    @classmethod
    def oucscodes(cls, query, only_app, request):
        if not cls.OUCSCODE_RE.match(query.upper()):
            return []

        try:
            json = simplejson.load(urllib2.urlopen(
                'http://m.ox.ac.uk/oxpoints/oucs:%s.json' % query.lower()))
        except urllib2.HTTPError:
            return []

        results = []
        for result in json:
            try:
                entity = Entity.objects.get(oxpoints_id=result['uri'][-8:])
            except Entity.DoesNotExist:
                continue

            metadata = EntityDetailView.get_metadata(request, entity.entity_type.slug, entity.display_id)

            metadata.update({
                'redirect_if_sole_result': True,
                'url': entity.get_absolute_url(),
github codiez / python-foursquare / foursquare.py View on Github external
request = urllib2.Request('%s?%s' % (query_url, data) )
            else:
                request = urllib2.Request(query_url)
        else:
            if params:
                data = urllib.urlencode(params)
                request = urllib2.Request(query_url, data)
            else:
                request = urllib2.Request(query_url)

        if username and password:
            b64 = base64.encodestring('%s:%s' % (username, password))[:-1]
            authheader="Basic %s" % b64
            request.add_header('Authorization', authheader)
        try:
            result = simplejson.load(urllib2.urlopen(request))
        except IOError, e:
            result = simplejson.load(e)
        return result
github odoo / odoo / openerpweb / openerpweb.py View on Github external
:param controller: the instance of the controller which received the request
        :type controller: type
        :param method: the method which received the request
        :type method: callable
        :param requestf: a file-like object containing an encoded JSON-RPC2 request
        :type requestf:  bytes>
        :param request: an encoded JSON-RPC2 request
        :type request: bytes

        :returns: a string-encoded JSON-RPC2 reply
        :rtype: bytes
        '''
        # Read POST content or POST Form Data named "request"
        if requestf:
            request = simplejson.load(requestf, object_hook=nonliterals.non_literal_decoder)
        else:
            request = simplejson.loads(request, object_hook=nonliterals.non_literal_decoder)
        try:
            print "--> %s.%s %s" % (controller.__class__.__name__, method.__name__, request)
            error = None
            self.parse(request)
            result = method(controller, self, **self.params)
        except OpenERPUnboundException:
            error = {
                'code': 100,
                'message': "OpenERP Session Invalid",
                'data': {
                    'type': 'session_invalid',
                    'debug': traceback.format_exc()
                }
            }
github Galts-Gulch / avarice / okcoin_api.py View on Github external
sign_string += key + '=' + str(params[key])
            if(pos != len(params) - 1):
                sign_string += '&'

        sign_string += self.secret
        m = hashlib.md5()
        m.update(sign_string.encode('utf-8'))
        signed = m.hexdigest().upper()

        params['sign'] = signed

        data = urllib.parse.urlencode(params)
        binary_data = data.encode('utf-8')
        req = urllib.request.Request(url, binary_data)
        response = urllib.request.urlopen(req)
        result = simplejson.load(response)

        success = result['result']
        if(not success):
            print(('Error: ' + str(result['errorCode'])))
            print((self.error_code_meaning(result['errorCode'])))
            return(result)
        else:
            return(result)
github ryanmcgrath / twython / build / lib / twython.py View on Github external
def getBlocking(self, page = "1"):
		if self.authenticated is True:
			try:
				return simplejson.load(self.opener.open("http://twitter.com/blocks/blocking.json?page=" + page))
			except HTTPError, e:
				raise TangoError("getBlocking() failed with a %s error code." %	`e.code`, e.code)
		else:
			raise TangoError("getBlocking() requires you to be authenticated")