|
19 | 19 |
|
20 | 20 | from twarc.version import version
|
21 | 21 | from twarc.handshake import handshake
|
| 22 | +from twarc.config import ConfigProvider |
22 | 23 | from twarc.decorators import cli_api_error
|
23 | 24 | from twarc.expansions import ensure_flattened
|
24 | 25 | from click_config_file import configuration_option
|
25 | 26 |
|
| 27 | +config_provider = ConfigProvider() |
26 | 28 |
|
27 | 29 | @with_plugins(iter_entry_points('twarc.plugins'))
|
28 | 30 | @click.group()
|
|
42 | 44 | show_default=True,
|
43 | 45 | )
|
44 | 46 | @click.option('--log', default='twarc.log')
|
| 47 | +@click.option('--verbose', is_flag=True, default=False) |
45 | 48 | @click.option('--metadata/--no-metadata', default=True, show_default=True,
|
46 | 49 | help="Include/don't include metadata about when and how data was collected.")
|
47 |
| -@configuration_option(cmd_name='twarc') |
| 50 | +@configuration_option(cmd_name='twarc', config_file_name='config', provider=config_provider) |
48 | 51 | @click.pass_context
|
49 | 52 | def twarc2(
|
50 | 53 | ctx, consumer_key, consumer_secret, access_token, access_token_secret, bearer_token,
|
51 |
| - log, metadata, app_auth |
| 54 | + log, metadata, app_auth, verbose |
52 | 55 | ):
|
53 | 56 | """
|
54 | 57 | Collect data from the Twitter V2 API.
|
55 | 58 | """
|
56 | 59 | logging.basicConfig(
|
57 | 60 | filename=log,
|
58 |
| - level=logging.INFO, |
| 61 | + level=logging.DEBUG if verbose else logging.INFO, |
59 | 62 | format="%(asctime)s %(levelname)s %(message)s"
|
60 | 63 | )
|
61 | 64 |
|
| 65 | + logging.info("using config %s", config_provider.file_path) |
| 66 | + |
62 | 67 | if bearer_token or (consumer_key and consumer_secret):
|
63 | 68 | if app_auth and (bearer_token or (consumer_key and consumer_secret)):
|
64 | 69 | ctx.obj = twarc.Twarc2(
|
@@ -103,15 +108,14 @@ def configure(ctx):
|
103 | 108 | """
|
104 | 109 | Set up your Twitter app keys.
|
105 | 110 | """
|
| 111 | + |
| 112 | + config_file = config_provider.file_path |
| 113 | + logging.info('creating config file: %s', config_file) |
| 114 | + |
106 | 115 | keys = handshake()
|
107 | 116 | if keys is None:
|
108 | 117 | raise click.ClickException("Unable to authenticate")
|
109 | 118 |
|
110 |
| - config_dir = pathlib.Path(click.get_app_dir('twarc')) |
111 |
| - if not config_dir.is_dir(): |
112 |
| - config_dir.mkdir(parents=True) |
113 |
| - config_file = config_dir / 'config' |
114 |
| - |
115 | 119 | config = configobj.ConfigObj(unrepr=True)
|
116 | 120 | config.filename = config_file
|
117 | 121 |
|
@@ -682,3 +686,12 @@ def _error_str(errors):
|
682 | 686 | def _write(results, outfile, pretty=False):
|
683 | 687 | indent = 2 if pretty else None
|
684 | 688 | click.echo(json.dumps(results, indent=indent), file=outfile)
|
| 689 | + |
| 690 | +""" |
| 691 | +def _get_config_file(): |
| 692 | + config_dir = pathlib.Path(click.get_app_dir('twarc')) |
| 693 | + if not config_dir.is_dir(): |
| 694 | + config_dir.mkdir(parents=True) |
| 695 | + config_file = config_dir / 'config' |
| 696 | + return config_file |
| 697 | +""" |
0 commit comments