def select(self, cr, mql='*', datas=None, **kargs): if not isinstance(cr, Cursor): raise Exception('cr parameter must be a cursor class got this instead: %s' % repr(cr)) #try: # mql = cr(self)._safe_sql(mql, datas) #except: #"" if 'debug' in cr.context and cr.context['debug']: # raise # return [] sql_query = SQLQuery(self) return sql_query.get_array(cr, mql, datas, **kargs)
def get_scalar(self, cr, mql, datas=None): """Return simple list with first column of result""" if not isinstance(cr, Cursor): raise Exception('cr parameter must be a cursor class got this instead %s' % repr(cr)) try: mql = cr(self)._safe_sql(mql, datas) except: if 'debug' in cr.context and cr.context['debug']: raise return [] sql_query = SQLQuery(self) return sql_query.get_scalar(cr, mql)
def insert_runs(): pass def drop_tables(): pass def drop_status_enum(): pass if __name__ == '__main__': command = sys.argv[1] print('command: ', command) if command == 'create-tables': sql_query = SQLQuery( 'SELECT * FROM simulation_step WHERE simulation_run_id=2 LIMIT 10;' ) sql_query.execute() elif command == 'drop-tables': sql_query = SQLQuery( 'SELECT * FROM simulation_step WHERE simulation_run_id=2 LIMIT 10;' ) sql_query.execute() elif command == 'insert-runs': sql_query = SQLQuery( 'SELECT * FROM simulation_step WHERE simulation_run_id=2 LIMIT 10;' ) sql_query.execute()
class TopGG(commands.Cog): def __init__(self, bot): self.bot = bot self.sql_query = SQLQuery(initialize_connection()) self.manager = Manager() self.stitcher = Stitcher() self.dbl_token = config('DBL_TOKEN') self.webhook_auth_token = config('ALICE_WEBHOOK_AUTH_TOKEN') self.dblpy = dbl.DBLClient(self.bot, self.dbl_token, autopost=True, webhook_path='/dblwebhook', webhook_auth=self.webhook_auth_token, webhook_port=environ.get("PORT", 8000)) @commands.Cog.listener() async def on_dbl_vote(self, data): user_id = int(data['user']) user = await self.bot.fetch_user(user_id) thumbnail_data = self.stitcher.stitch_images( f'https://cdn.discordapp.com/avatars/{user.id}/{user.avatar}.png?size=1024', './static/images/medal.png') try: query_string_params = data['query'][1:].split('&') param_dict = { param.split('=')[0]: int(param.split('=')[1]) for param in query_string_params } except Exception as e: param_dict = {} print(e, param_dict) try: if param_dict: guild_triggered_in = [ guild for guild in self.bot.guilds if guild.id == param_dict.get('guild') ][0] channel_trigged_in = guild_triggered_in.get_channel( param_dict.get('channel')) embed = self.manager.create_embed( f'{user.name} has voted!', 'Thank you valued patron for supporting alice.' ' Your contribution will not go in vain as I award you the highest prestige I can bestow.' ' Your name will echo through the decades to come, enscribed with the flow of light on alloy whose origins stem from the creation of Earth.' ' Now come hero, accept your award and be off to privilege our world with more of your good deeds.', 0xFFA500, 'attachment://user_awarded.png', ['Award'], ['You got a one of a kind medallion!'], footer=[ f'{user.name} \u2022 {self.manager.current_time()}', user.avatar_url ]) await channel_trigged_in.send(embed=embed, file=discord.File( thumbnail_data, 'user_awarded.png')) self.sql_query.update_by_increment('guilds', ['vote_count'], ['guild_id'], [[param_dict.get('guild')]]) else: embed = self.manager.create_embed( 'You voted!', 'Thank you valued patron for supporting alice.' ' Your contribution will not go in vain as I award you the highest prestige I can bestow.' ' Your name will echo through the decades to come, enscribed with the flow of light on alloy whose origins stem from the creation of Earth.' ' Now come hero, accept your award and be off to privilege our world with more of your good deeds.', 0xFFA500, 'attachment://user_awarded.png', ['Award'], ['You got a one of a kind medallion!'], footer=[ f'{user.name} \u2022 {self.manager.current_time()}', user.avatar_url ]) await user.send(embed=embed, file=discord.File(thumbnail_data, 'user_awarded.png')) except Exception as e: print('dbl_vote ' + str(e)) @commands.Cog.listener() async def on_dbl_test(self, data): print(data)
def _get_sql_query(self): return SQLQuery(self)
def sql(self, cr, sql, **kargs): if not isinstance(cr, Cursor): raise Exception('cr parameter must be a cursor class got this instead: %s' % repr(cr)) sql_query = SQLQuery(self) return sql_query.get_array_sql(cr, sql, **kargs)