示例#1
0
    def write_block(self, block, durability='soft'):
        """Write a block to bigchain.

        Args:
            block (dict): block to write to bigchain.
        """

        block_serialized = rapidjson.dumps(block)
        r.table('bigchain').insert(r.json(block_serialized), durability=durability).run(self.conn)
示例#2
0
 def test_update_with_json(self, conn):
     expected = [
         {'id': 'one', 'nums': [1, 2, 3]},
         {'id': 'two', 'nums': [1, 2, 3]}
     ]
     result = r.db('d').table('t').map(
         lambda doc: doc.merge(r.json('{"nums": [1, 2, 3]}'))
     ).run(conn)
     assertEqUnordered(expected, list(result))
示例#3
0
    def write_block(self, block, durability='soft'):
        """Write a block to bigchain.

        Args:
            block (dict): block to write to bigchain.
        """

        block_serialized = rapidjson.dumps(block)
        r.table('bigchain').insert(r.json(block_serialized), durability=durability).run(self.conn)
示例#4
0
    def write_block(self, block, durability='soft'):
        """Write a block to bigchain.

        Args:
            block (Block): block to write to bigchain.
        """

        self.connection.run(
            r.table('bigchain').insert(r.json(block.to_str()),
                                       durability=durability))
示例#5
0
    def write_block(self, block, durability='soft'):
        """Write a block to the bigchain table.

        Args:
            block (dict): the block to write.

        Returns:
            The database response.
        """
        return self.connection.run(
            r.table('bigchain').insert(r.json(block), durability=durability))
示例#6
0
文件: fetch.py 项目: vierja/livemvd
def get_variant_information(variant_id):
    url = VARIANT_PATH.format(variant_id)
    r = requests.get(url)
    if r.status_code == 0:
        resp = r.json()
        if 'Name' in resp and len(resp['Name']) > 0:
            yield {
                'name': resp['Name'],
                'points': resp['Points'],
                'variation_id': resp['VariationId'],
            }
示例#7
0
文件: fetch.py 项目: vierja/livemvd
def get_variant_information(variant_id):
    url = VARIANT_PATH.format(variant_id)
    r = requests.get(url)
    if r.status_code == 0:
        resp = r.json()
        if 'Name' in resp and len(resp['Name']) > 0:
            yield {
                'name': resp['Name'],
                'points': resp['Points'],
                'variation_id': resp['VariationId'],
            }
示例#8
0
 def test_update_with_json(self, conn):
     expected = [{
         'id': 'one',
         'nums': [1, 2, 3]
     }, {
         'id': 'two',
         'nums': [1, 2, 3]
     }]
     result = r.db('d').table('t').map(
         lambda doc: doc.merge(r.json('{"nums": [1, 2, 3]}'))).run(conn)
     assertEqUnordered(expected, list(result))
示例#9
0
    def write_block(self, block, durability='soft'):
        """Write a block to the bigchain table.

        Args:
            block (dict): the block to write.

        Returns:
            The database response.
        """
        return self.connection.run(
                r.table('bigchain')
                .insert(r.json(block), durability=durability))
示例#10
0
 def register(self):
     try:
         req= requests.post(self.url+'/register' ,allow_redirects=False, verify=False, timeout=3)
         if req.status_code==200:
             with app.app_context():
                 r.table('config').get(1).update({'resources':{'code':req.json()}}).run(db.conn)
                 self.code=req.json()
                 self.updateFromConfig()
                 self.updateFromWeb()
                 return True
         else:
             print('Error response code: '+str(req.status_code)+'\nDetail: '+r.json())
     except Exception as e:
         print("Error contacting.\n"+str(e))
     return False
示例#11
0
文件: general.py 项目: JLexD/LUL
 async def status(self, ctx):
     async with ctx.channel.typing():
         msgs = await lang.get_lang(ctx)
         e = discord.Embed(color=discord.Color(0x6441A4),
                           title=msgs['general']['status']['title'])
         r = requests.get(
             "https://cjn0pxg8j9zv.statuspage.io/api/v2/summary.json")
         r.raise_for_status()
         r = r.json()["components"]
         for c in r:
             emote = lang._emoji.cmd_success
             if c["status"] in ["partial_outage", "major_outage"]:
                 emote = lang.emoji.cmd_fail
             e.add_field(
                 name="{}{}".format(emote, c["name"]),
                 value=msgs['general']['status']['current_status'].format(
                     status=c['status']),
                 inline=False)
     await ctx.send(embed=e)
示例#12
0
 def register(self):
     try:
         req = requests.post(self.url + '/register',
                             allow_redirects=False,
                             verify=False,
                             timeout=3)
         if req.status_code == 200:
             with app.app_context():
                 r.table('config').get(1).update({
                     'resources': {
                         'code': req.json()
                     }
                 }).run(db.conn)
                 self.updateFromConfig()
                 self.updateFromWeb()
                 return True
         else:
             print('Error response code: ' + str(req.status_code) +
                   '\nDetail: ' + r.json())
     except Exception as e:
         print("Error contacting.\n" + str(e))
     return False
示例#13
0
 def register_isard_updates(self):
     if not self.register_isard:
         return False
     else:
         # USER WANTS TO REGISTER ISARD
         try:
             cfg = r.table('config').get(1).pluck('resources').run()
         except Exception as e:
             return False
         if 'resources' in cfg.keys():
             self.url = cfg['resources']['url']
             self.code = cfg['resources']['code']
         if self.code is False:
             if self.url is False: self.url = 'http://www.isardvdi.com:5050'
             try:
                 req = requests.post(self.url + '/register',
                                     allow_redirects=False,
                                     verify=False,
                                     timeout=3)
                 if req.status_code == 200:
                     self.code = req.json()
                     r.table('config').get(1).update({
                         'resources': {
                             'url': self.url,
                             'code': req.json()
                         }
                     }).run()
                     wlog.warning('Isard app registered')
                     return True
                 else:
                     wlog.info(
                         'Isard app registering error response code: ' +
                         str(req.status_code) + '\nDetail: ' + r.json())
                     return False
             except Exception as e:
                 wlog.warning("Error contacting.\n" + str(e))
                 return False
     return True
示例#14
0
def write_block(connection, block_dict):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(serialize(block_dict)), durability=WRITE_DURABILITY))
示例#15
0
文件: query.py 项目: cgwyx/bigchaindb
def write_block(connection, block_dict):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(serialize(block_dict)), durability=WRITE_DURABILITY))
示例#16
0
 def post(self):
     conn = yield self.application.conn
     yield rethinkdb.table("dhcpserverstats").insert(
         rethinkdb.json(self.request.body)).run(conn)
示例#17
0
def write_block(connection, block):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(block.to_str()), durability=WRITE_DURABILITY))
示例#18
0
def write_block(connection, block):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(block.to_str()), durability=WRITE_DURABILITY))