Python ujson.decode() Examples

The following are code examples for showing how to use ujson.decode(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: script-languages   Author: exasol   File: external_modules.py    MIT License 6 votes vote down vote up
def setUp(self):
        self.query('DROP SCHEMA t1 CASCADE', ignore_errors=True)
        self.query('CREATE SCHEMA t1')
   
        self.query(dedent('''\
                CREATE python3 SCALAR SCRIPT
                ujson_decode(json VARCHAR(10000))
                RETURNS VARCHAR(10000) AS
                import json
                import ujson
                def run(ctx):
                    return json.dumps(ujson.decode(ctx.json))
                '''))
    
        self.query(dedent('''\
                CREATE python3 SCALAR SCRIPT
                ujson_encode(json VARCHAR(10000))
                RETURNS VARCHAR(10000) AS

                import json
                import ujson

                def run(ctx):
                    return ujson.encode(json.loads(ctx.json))
                ''')) 
Example 2
Project: Facebook_PyBot   Author: hundredeir   File: message.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def updates(callback):
    """
    This function takes the callback as an input and creates an instance for each message received and stores
    it(instance) into an array. Which is then returned
    
    :param callback: contains the callback from facebook.
    :return: array of Message instances.
    
    """
    entries = []
    try:
        callback = json.decode(callback)
    except:
        pass
    for entry in callback["entry"]:
        messaging = entry["messaging"]
        messages = [Message(data) for data in messaging]
        entries.extend(messages)
    return entries 
Example 3
Project: dsc-crawler   Author: royburns   File: dsc-crawler_test.py    Apache License 2.0 5 votes vote down vote up
def get_user_info(user_id):

    print '111'
    url_api = 'api/user'
    headers = {
        'Host': "dscapp.dscun.com",
        'meet-token': '0ccbe9212e7640a904d41ee477076227',
        'Proxy-Connection': 'keep-alive',
        'client-version': '3.4.6.1',
        'Connection': 'keep-alive',
        'os-type': 'iOS',
        'User-Agent': '单身村 3.4.6 rv:3.4.6.1 (iPhone; iOS 10.2; zh_CN)',
        'app-version': '2.0.1',
        'Accept-Encoding': 'gzip'
    }

    data = {'login': '******',
            'pass': '******'
            }

    s = '{}/{}/{}'.format(URL, url_api, user_id)
    # print s
    # 'https://dscapp.dscun.com/api/user/86052'
    r = requests.get(s, headers=headers, json=data)

    print(r.status_code)
    print(r.reason)
    # print(r.text)
    decoded = ujson.decode(r.text)['data']
    for x in decoded:
        print u'{}: {} -- type: {}'.format(x, decoded[x], type(decoded[x]))

    print(decoded['id'])

    pass 
Example 4
Project: Facebook_PyBot   Author: hundredeir   File: send.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_user_info(self, user_id):
        """
        
        The User Profile API lets your bot get more information about the user
        for more info go to https://developers.facebook.com/docs/messenger-platform/user-profile
        
        :param user_id: User id of the person of whom user info is to be retrieved.
        :type user_id: str
        :return: first name,last name,profile pic,locale,timezone,gender.
        
        """
        url = self.URL.format(user_id)
        key = {"fields": "first_name,last_name,profile_pic,locale,timezone,gender",
               "access_token": self.Access_Token
               }
        response = requests.get(url, params=key)
        data = response.json()
        try:
            data = json.decode(data)
        except:
            pass
        try:
            return data["first_name"], data["last_name"], data["profile_pic"], data["locale"], data["timezone"], data[
                "gender"]
        except:
            return None 
Example 5
Project: policy_diffusion   Author: dssg   File: state_bill_extractors.py    MIT License 5 votes vote down vote up
def tn_text_extractor(data_source):
    return ' '.join(line for line in pdfdata_to_text(data_source).splitlines()
                    if re.findall('[a-z]', line)).decode('utf8') 
Example 6
Project: pyspark-elastic   Author: TargetHolding   File: rdd.py    Apache License 2.0 5 votes vote down vote up
def loads(self):
		return self.mapValues(lambda v: json.loads(v.decode('utf-8'))) 
Example 7
Project: pyspark-elastic   Author: TargetHolding   File: rdd.py    Apache License 2.0 5 votes vote down vote up
def loadsObj(self):
		return self.mapValues(lambda v: AttrDict.loads(v.decode('utf-8'))) 
Example 8
Project: policy_diffusion   Author: dssg   File: state_bill_extractors.py    MIT License 4 votes vote down vote up
def test_bill_extractors():

    base_path = "/mnt/data/sunlight/dssg/scraped_bills/"
    state_codes = os.listdir("/mnt/data/sunlight/dssg/scraped_bills/")


    for state_code in state_codes:
        data_path = "{0}/{1}".format(base_path,state_code)
        bill_files = []
        for dirname, dirnames, filenames in walk(data_path):
            for filename in filenames:
                bill_files.append(os.path.join(dirname, filename))

        random.shuffle(bill_files)

        num_tests = 10
        num_errors = 0
        for i,bill_file in enumerate(bill_files[0:num_tests]):
            json_obj = ujson.decode(open(bill_file).read())


            try:
                bill_document = base64.b64decode(json_obj['versions'][0]['bill_document'])
            except:
                num_tests -= 1
                continue


            try:
                mimetype = json_obj['versions'][0]['mimetype']
            except KeyError:
                mimetype = json_obj['versions'][0]['+mimetype']


            bill_text = bill_text_extractor(state_code,bill_document,mimetype,json_obj['versions'][0]['url'])

            if bill_text == None:
                num_errors +=1


        if 100*(1-(num_errors/num_tests)) < 100.0:

            output =  "passed {:.2f}% number of tests for state {:s} with {:d} tests".format(
                100*(1-(num_errors/num_tests)),state_code,num_tests)
            print output.upper()