Exemplo n.º 1
0
def api_v1_convert_screen_names_to_ids(request):
    api = get_api('sakuramochi_pre')
    data = json.loads(request.body.decode("utf-8"))
    screen_names = data['screen_names']
    ids = []
    for screen_name in screen_names:
        try:
            user = api.get_user(screen_name=screen_name)
            ids.append(user.id_str)
        except tweepy.TweepError:
            ids.append('???')

    data = {'ids': ids}
    response = JsonResponse(data)
    response['Access-Control-Allow-Origin'] = '*'
    return response
Exemplo n.º 2
0
    r = requests.get(url)
    r.encoding = encoding
    return BeautifulSoup(r.text, 'lxml')


if __name__ == '__main__':
    # Parse command line args
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', '-d', action='store_true')
    parser.add_argument('target')
    parser.add_argument('command',
                        choices=[
                            'save_all_pages',
                            'save_new_page',
                            'tweet_new_docs',
                        ])
    args = parser.parse_args()

    # Load config
    config = get_config(args.target)
    if not config:
        sys.exit(1)

    # Get twitter api
    if args.debug:
        api = get_api(config['debug_account'])
    else:
        api = get_api(config['account'])

    main(args)
Exemplo n.º 3
0
    trs = s.select('.shopSelect tbody tr')
    for tr in trs:
        date = tr.select('th')[0].text.replace('\n', '')
        btn = tr.select('.btn')[0]

        if btn.text == '終了':
            continue
        # 満席の場合 "close" が含まれる
        elif 'close' in btn['class']:
            status = '現在「{date}」\nの予約は満席です!\n#プリリズカフェ [{now}時点]'.format(
                date=date, now=get_now_string())
            tweet(status)
        else:
            date_url = urljoin(url, btn['href'])
            tweet_for_date(date, date_url)


if __name__ == '__main__':
    # parse args
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--debug', action='store_true')
    args = parser.parse_args()

    if args.debug:
        api = get_api('sakuramochi_pre')
    else:
        api = get_api('prism_cafe_bot')
    br = PhantomJS()

    main()
    with open('settings.yaml') as f:
        settings = yaml.load(f).get(account)
    if not settings:
        raise ValueError('There is no account name', account)
    return settings

if __name__ == '__main__':
    print(datetime.datetime.now())

    IGNORE_USERS = get_ignore_users()
    IGNORE_DATES = get_ignore_dates()
    IGNORE_IDS = get_ignore_ids()
    
    parser = argparse.ArgumentParser()
    parser.add_argument('account')
    parser.add_argument('command', choices=['retweet', 'update_themes'])
    parser.add_argument('--dry-run', action='store_true')
    args = parser.parse_args()

    settings = get_settings(args.account)
    print(settings)
    api = get_api(settings['rt_bot_screen_name'])
    tag = settings['tag']
    tws = get_mongo_client()[settings['db_name']].tweets
    ths = get_mongo_client()[settings['db_name']].themes

    if args.command == 'retweet':
        retweet()
    elif args.command == 'update_themes':
        update_themes()
Exemplo n.º 5
0
                f'{WORK_NAME}\n'
                f'今日は公開 {days} 日目です{exclamation}\n'
                f'{space}#kinpri #prettyrhythm')

    return text


def get_exclamation_marks(days: int) -> str:
    """残り日数に応じて、数を変えた「!」を生成する"""
    if 0 < days <= 10:
        exclamation_num = 3
    elif days % 10 == 0:
        exclamation_num = 2
    else:
        exclamation_num = 1
    exclamation = '!' * exclamation_num
    return exclamation


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', '-d', action='store_true')
    args = parser.parse_args()

    screen_name = 'kinpricountdown'
    if args.debug:
        screen_name = 'sakuramochi_pre'
    api = get_api(screen_name)

    tweet()
Exemplo n.º 6
0
        settings = yaml.load(f).get(account)
    if not settings:
        raise ValueError('There is no account name', account)
    return settings


if __name__ == '__main__':
    print(datetime.datetime.now())

    IGNORE_USERS = get_ignore_users()
    IGNORE_DATES = get_ignore_dates()
    IGNORE_IDS = get_ignore_ids()

    parser = argparse.ArgumentParser()
    parser.add_argument('account')
    parser.add_argument('command', choices=['retweet', 'update_themes'])
    parser.add_argument('--dry-run', action='store_true')
    args = parser.parse_args()

    settings = get_settings(args.account)
    print(settings)
    api = get_api(settings['rt_bot_screen_name'])
    tag = settings['tag']
    tws = get_mongo_client()[settings['db_name']].tweets
    ths = get_mongo_client()[settings['db_name']].themes

    if args.command == 'retweet':
        retweet()
    elif args.command == 'update_themes':
        update_themes()
Exemplo n.º 7
0
        'retweet', 'follow',
        'run_command_from_tos',
    ])
    parser.add_argument('--date')
    parser.add_argument('--delta', type=int, default=1)
    parser.add_argument('--screen_names', nargs='+')  # for retweet
    parser.add_argument('--ids', nargs='+')  # for retweet

    args = parser.parse_args()

    # prepare database
    c = get_mongo_client().kinpri_goods_wiki

    # get tweepy api
    if args.debug:
        api = get_api('sakuramochi_pre')
    else:
        api = get_api('goods_yamada')

    # run command

    # today
    if args.command == 'tweet_today':
        tweet_date_items(get_date())

    elif args.command == 'print_today':
        print_date_items(get_date())

    # tomorrow
    if args.command == 'tweet_tomorrow':
        tweet_date_items(get_date(delta=1))
Exemplo n.º 8
0
        

if __name__ == '__main__':
    # args
    parser = argparse.ArgumentParser()
    parser.add_argument('subcommand', choices=[
        'add_user',
        'delete_user',
        'save',
        'twisave',
    ])
    parser.add_argument('-u', '--user')
    args = parser.parse_args()

    # twitter api
    api = get_api('sakuramochi_0')

    # mongodb client
    cli = get_mongo_client()
    db = cli.twive

    # logger
    logger = logging.getLogger('twive')
    logging.basicConfig(level=logging.INFO)

    if args.subcommand == 'add_user':
        if args.user:
            add_user(args.user)
        else:
            parser.print_help()
    elif args.subcommand == 'delete_user':
Exemplo n.º 9
0
    parser.add_argument('command', choices=[
        'inform',
        'retweet',
        'fetch_tos',
        'check_replies',
        'convert_birthday_to_csv',
        'update_birthday_spreadsheet',
        'add_ignore_users',
        'remove_ignore_users',
    ])
    parser.add_argument('--users', '-u', nargs='+')
    parser.add_argument('--target_works', nargs='+')
    parser.add_argument('--ids', nargs='+')
    args = parser.parse_args()

    api = get_api(args.account)
    tws = get_mongo_client()[api.auth.username].tweets
    replies = get_mongo_client()[api.auth.username].replies
    
    if args.command == 'inform':
        inform()
    elif args.command == 'retweet':
        if args.ids:
            retweet(args.ids)
        else:
            retweet()
    elif args.command == 'fetch_tos':
        fetch_tos()
    elif args.command == 'check_replies':
        check_replies()
    elif args.command == 'convert_birthday_to_csv':
Exemplo n.º 10
0
                            'follow',
                            'run_command_from_tos',
                        ])
    parser.add_argument('--date')
    parser.add_argument('--delta', type=int, default=1)
    parser.add_argument('--screen_names', nargs='+')  # for retweet
    parser.add_argument('--ids', nargs='+')  # for retweet

    args = parser.parse_args()

    # prepare database
    c = get_mongo_client().kinpri_goods_wiki

    # get tweepy api
    if args.debug:
        api = get_api('sakuramochi_pre')
    else:
        api = get_api('goods_yamada')

    # run command

    # today
    if args.command == 'tweet_today':
        tweet_date_items(get_date())

    elif args.command == 'print_today':
        print_date_items(get_date())

    # tomorrow
    if args.command == 'tweet_tomorrow':
        tweet_date_items(get_date(delta=1))