Beispiel #1
0
    def __init__(self, baseplate, lock, *args, **kwargs):
        super().__init__(baseplate, lock, acl=kwargs.get('acl'))

        self._set_bot_thread()
        self._set_defaults(kwargs)
        for prop in [
            'secret_word_channels',
            'disbursement_channels',
            'participant_channels'
        ]:
            if hasattr(self, prop):
                setattr(self,  prop, [
                    self.botThread.get_channel_id_by_name(channel)
                    for channel in getattr(self, prop)
                ])

        # set tx locations and load/initialize db
        tables = {}
        table_dir = os.path.join(LOCAL_DIR, 'data', 'tables')
        for _file in os.listdir(table_dir):
            path = os.path.join(table_dir, _file)
            if os.path.isfile(path):
                tables.update(file.load_file(path))

        migrations = {}
        migr_dir = os.path.join(LOCAL_DIR, 'data', 'table_migrations')
        for _file in os.listdir(migr_dir):
            path = os.path.join(migr_dir, _file)
            if os.path.isfile(path):
                migrations.update(file.load_file(path))

        self._init_tx_db(tables, kwargs.get('seeds', {}), migrations)
Beispiel #2
0
def run9() -> tuple[str, str]:
    places = set()

    def format_data(str: str) -> tuple[str, str, int]:
        split = str.split(' ')
        place_a, place_b = split[0], split[2]
        places.add(place_a)
        places.add(place_b)
        return (place_a, place_b, int(split[-1]))

    data = FluxList(load_file(9, True)) \
        .map(lambda s, i : format_data(s))

    places = list(places)
    places.sort()

    data = data \
        .map(lambda x, i : (places.index(x[0]), places.index(x[1]), x[2]))

    places_count = len(places)

    grid = [[0 for _ in range(places_count)] for _ in range(places_count)]

    for i in range(data.count()):
        cell_data = data.at(i)
        grid[cell_data[0]][cell_data[1]] = cell_data[2]
        grid[cell_data[1]][cell_data[0]] = cell_data[2]

    return ("", "")
Beispiel #3
0
def run8() -> tuple[str, str]:
    data = FluxList(load_file(8, True))

    result_1 = data \
        .map(lambda s, i : (get_code_length(s), get_str_length(s))) \
        .crumple(lambda a, b : (a[0] + b[0], a[1] + b[1]))

    result_2 = data \
        .map(lambda s, i : get_extra_encode_length(s)) \
        .crumple(lambda a, b : a + b)

    return (result_1[0] - result_1[1], result_2)
Beispiel #4
0
def main():
    days = map_as_list(int, sys.argv[1:])
    if len(days) == 0:
        days = range(1, 26)

    print('Running the following days:\n' + ', '.join(map(str, days)) + '\n')

    for day in days:
        try:
            data = load_file(day)
            code = importlib.import_module(f'days._{day}_code')
        except:
            print(f'Files for day {day} don\'t exist, exiting...\n')
            return

        print(day, code.run(data))
    
    print()
Beispiel #5
0
    def _init_board(self, name, cfg):
        get_history = False
        f_type = cfg.get('file_type', 'json')
        f_name = f'{name.lower()}.{f_type}'
        cfg['path'] = os.path.join(DATA_DIR, f_name)
        data = load_file(cfg['path'], f_type=f_type, default=[])
        channels = cfg.pop('channels', ['general'])
        channels = [self.botThread.get_channel_id_by_name(c) for c in channels]

        if not os.path.isfile(cfg['path']):
            get_history = True

        for channel in channels:
            if channel not in self.channels:
                self.channels[channel] = set()

            self.channels[channel].add(name)

        self.boards[name] = {'data': data, 'config': cfg}

        if get_history is True:
            for channel in channels:
                messages = call_slack_api(self.botThread.slack_client,
                                          'conversations.history',
                                          True,
                                          'messages',
                                          channel=channel)
                transform = ('[].{text: text, metadata: {source_channel: '
                             f'`{channel}`'
                             ', source_user: user, ts: ts}}')
                messages = jsearch(transform, messages)

                for message in messages:
                    self._process_board(message, name)

                LOGGER.debug('Channel history processed')
Beispiel #6
0
    def _load_moined(self):
        path = os.path.join(self.tx_dir, 'moined.json')
        if os.path.isfile(path):
            return file.load_file(path)

        return []
Beispiel #7
0
    def _load(self, prop):
        path = os.path.join(self.tx_dir, f'{prop}.json')
        if os.path.isfile(path):
            return file.load_file(path)

        return []
Beispiel #8
0
 def _init_user_map(self):
     self.user_map = load_file(
         os.path.join(LOCAL_DIR, 'data', 'aoc_map.yaml'))