Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 6
0
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'],
            }
Ejemplo n.º 7
0
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'],
            }
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 11
0
Archivo: general.py Proyecto: 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 14
0
def write_block(connection, block_dict):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(serialize(block_dict)), durability=WRITE_DURABILITY))
Ejemplo n.º 15
0
def write_block(connection, block_dict):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(serialize(block_dict)), durability=WRITE_DURABILITY))
Ejemplo n.º 16
0
 def post(self):
     conn = yield self.application.conn
     yield rethinkdb.table("dhcpserverstats").insert(
         rethinkdb.json(self.request.body)).run(conn)
Ejemplo n.º 17
0
def write_block(connection, block):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(block.to_str()), durability=WRITE_DURABILITY))
Ejemplo n.º 18
0
def write_block(connection, block):
    return connection.run(
            r.table('bigchain')
            .insert(r.json(block.to_str()), durability=WRITE_DURABILITY))