Ejemplo n.º 1
0
def main(file):
    db_utils.create_postgres_db()
    db.dal.connect()
    session = db.dal.Session()

    df = pd.read_excel(file)

    data_columns = [filter_feature, validation]

    data = df[data_columns]
    support_data = json.loads(df[df.columns.difference(data_columns)].to_json(orient='records'))

    for i in range(len(data)):

        data_row = data.iloc[i]
        support_data_row = support_data[i]

        data_obj = Data(filter_feature=str(data_row[filter_feature]), validation=int(data_row[validation]))
        session.add(data_obj)
        session.flush()
        support_data_obj = SupportData(support_data=support_data_row)
        data_obj.support_data = support_data_obj
        support_data_obj.data = data_obj
        support_data_obj.data_id = support_data_obj.data.id
        session.add(support_data_obj)

    session.commit()
    print(f'Loaded {len(data)} records of data and support_data.')
Ejemplo n.º 2
0
def insert_data(df, session):
    '''
    Insert data and supporting data into database
    '''

    filter_feature = 'Comments_Concatenated'
    validation = 'validated prediction'
    data_columns = [filter_feature, validation]

    data = df[data_columns]
    support_data = json.loads(
        df[df.columns.difference(data_columns)].to_json(orient='records'))

    for i in range(len(data)):

        data_row = data.iloc[i]
        support_data_row = support_data[i]

        data_obj = Data(filter_feature=str(data_row[filter_feature]),
                        validation=int(data_row[validation]))
        session.add(data_obj)
        session.flush()
        support_data_obj = SupportData(support_data=support_data_row)
        data_obj.support_data = support_data_obj
        support_data_obj.data = data_obj
        support_data_obj.data_id = support_data_obj.data.id
        session.add(support_data_obj)

    session.commit()
Ejemplo n.º 3
0
 async def servertrack(self, ctx, server=None, voiceChannel=None):
     """Server tracking is info"""
     if server:
         if voiceChannel:
             channel = self.bot.get_channel(int(voiceChannel))
             if channel:
                 await channel.edit(name="SERVERTRACKING")
                 data = await get(self.session,
                                  f"https://api.mcsrvstat.us/2/{server}")
                 self.bot.pool["serverTracking"][str(ctx.guild.id)] = {
                     "channel": voiceChannel,
                     "server": server
                 }
                 Data.save("", self.bot.pool)
                 if data["online"]:
                     name = f"{server.split('.')[0].title()}: {data['players']['online']:,} / {data['players']['max']:,}"
                     await channel.edit(name=name)
                 else:
                     await channel.edit(name="SERVER IS OFFLINE")
             else:
                 await ctx.send("I cannot find that channel")
         else:
             await ctx.send("Please provide a valid voice server ID")
     else:
         await ctx.send("Please provide a minecraft server")
Ejemplo n.º 4
0
 async def account_link(self, ctx, username=None):
     if username:
         uuid = await get_uuid(self.session, username)
         if uuid:
             self.bot.pool["user"][str(ctx.author.id)] = {"uuid": uuid}
             Data.save("", self.bot.pool)
             await ctx.send(f"Your account has been linked to {username}")
         else:
             await ctx.send("Please provide a valid username")
     else:
         await ctx.send(
             f"{ctx.message.author.mention}, :x: please provide a username")
Ejemplo n.º 5
0
    async def prefix(self, ctx, new_prefix):
        """Set a custom prefix for the bot commands"""
        cur_prefix = self.bot.pool["guilds"][str(ctx.guild.id)]["prefix"]

        if cur_prefix == new_prefix:
            await ctx.send(
                f"{ctx.author}, :ballot_box_with_cross: You are already using that as your set prefix for this guild.`"
            )
        else:
            data = self.bot.pool
            data["guilds"][str(ctx.guild.id)]["prefix"] = new_prefix
            Data.save("", data)
            self.bot.pool["guilds"][str(ctx.guild.id)]["prefix"] = new_prefix
            await ctx.send(
                f"{ctx.author}, :ballot_box_with_check: The prefix has been changed to `{new_prefix}`"
            )
Ejemplo n.º 6
0
def run_bot():
    log = logging.getLogger()

    try:
        pool = Data.connect("")
    except Exception as e:
        print('Could not load json database', file=sys.stderr)
        log.exception('Could not load json Exiting.')
        return

    bot = Obsidion()
    bot.pool = pool
    bot.run()
Ejemplo n.º 7
0
 async def serverlink_unlink(self, ctx):
     self.bot.pool["guilds"][str(ctx.guild.id)]["server"] = None
     Data.save("", self.bot.pool)
     await ctx.send(
         "Your discord server is no longer linked to a minecraft server")
Ejemplo n.º 8
0
 async def serverlink_link(self, ctx, server):
     self.bot.pool["guilds"][str(ctx.guild.id)]["server"] = server
     Data.save("", self.bot.pool)
     await ctx.send(f"Your discord server has been linked to {server}")
Ejemplo n.º 9
0
 async def account_unlink(self, ctx):
     self.bot.pool["user"][str(ctx.author.id)] = {"uuid": None}
     Data.save("", self.bot.pool)
     await ctx.send(
         "Your account has been unlinked from any minecraft account")