Exemplo n.º 1
0
    channels = response['channels']

    for idx, channel in enumerate(channels):
        chan_name = channel['name']
        print('{} | {} - {} MEMBERS'.format(idx, chan_name,
                                            channel['num_members']))

        chan_path = ensure_dir('./output/channels/{}'.format(chan_name))
        info_path = ensure_dir('./output/channels/{}/info'.format(chan_name))

        try:
            old_json = load_json('{}/{}.json'.format(info_path, chan_name))
            if not args['update']:
                print(
                    'Already have channel {}, skipping ...'.format(chan_name))
                continue
        except Exception as e:
            print(
                'No existing channel {} info, fetching ...'.format(chan_name))

        slack_args = {
            'channel': channel['id'],
        }

        channel_info = sc.api_call('channels.info', **slack_args)
        try:
            dump_json('{}/{}.json'.format(info_path, chan_name), channel_info)
        except Exception as e:
            print('ERROR DUMPING {}'.format(chan_name))
            print(e)
Exemplo n.º 2
0
        len(results['messages'])))
    return results['messages']


if __name__ == '__main__':
    config = load_json('./env.json')

    ap = argparse.ArgumentParser()
    ap.add_argument('-c', '--channel', help='channel id to scrape')
    ap.add_argument('-o', '--output', help='file to save out')
    args = vars(ap.parse_args())
    channel = args['channel']
    output = args['output']

    try:
        old_json = load_json(output)
    except Exception as e:
        old_json = []
        print('No existing messages, starting from scratch...')

    slack_args = {
        'channel': config['channel_id'],
        'oldest': old_json[0]['ts'] if len(old_json) else '',
    }

    new_messages = scrape_slack(config['token'], slack_args)

    if len(new_messages):
        all_messages = new_messages + old_json
        dump_json(output, all_messages)
Exemplo n.º 3
0
    ap = argparse.ArgumentParser()
    ap.add_argument('-u',
                    '--update',
                    help='update channels',
                    action="store_true")
    args = vars(ap.parse_args())

    slack_args = {'presence': 1}

    sc = SlackClient(config['token'])
    response = sc.api_call('users.list', **slack_args)
    users = response['members']

    for user in users:
        user_name = user['name']
        memb_path = ensure_dir('./output/users/members')
        user_path = '{}/{}.json'.format(memb_path, user_name)

        try:
            old_json = load_json(user_path)
            if not args['update']:
                print('Aready have user {}, skipping...'.format(user_name))
                continue
        except Exception as e:
            old_json = {}
            print('No existing messages, starting from scratch...')

        print('ADDING ', user_name)

        dump_json(user_path, user)