Skip to content

Commit

Permalink
Merge pull request #109 from xenova/facebook
Browse files Browse the repository at this point in the history
Improved site testing
  • Loading branch information
xenova committed Jul 27, 2021
2 parents cdd939f + a33b43b commit 705a7dd
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 293 deletions.
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ Command line
[--end_time END_TIME]
[--message_types MESSAGE_TYPES | --message_groups MESSAGE_GROUPS]
[--max_attempts MAX_ATTEMPTS]
[--retry_timeout RETRY_TIMEOUT] [--interruptible_retry]
[--retry_timeout RETRY_TIMEOUT]
[--interruptible_retry [INTERRUPTIBLE_RETRY]]
[--max_messages MAX_MESSAGES]
[--inactivity_timeout INACTIVITY_TIMEOUT]
[--timeout TIMEOUT] [--format FORMAT]
[--format_file FORMAT_FILE] [--chat_type {live,top}]
[--ignore IGNORE]
[--message_receive_timeout MESSAGE_RECEIVE_TIMEOUT]
[--buffer_size BUFFER_SIZE] [--output OUTPUT]
[--overwrite] [--sort_keys] [--indent INDENT]
[--pause_on_debug | --exit_on_debug]
[--overwrite [OVERWRITE]] [--sort_keys [SORT_KEYS]]
[--indent INDENT] [--pause_on_debug | --exit_on_debug]
[--logging {none,debug,info,warning,error,critical} | --testing | --verbose | --quiet]
[--cookies COOKIES] [--proxy PROXY]
url
Expand Down
45 changes: 25 additions & 20 deletions chat_downloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

from .utils.core import (
get_default_args,
int_or_none,
splitter
int_or_none
)

from .debugging import (
Expand All @@ -27,6 +26,23 @@
)


def splitter(s):
return [item.strip() for item in re.split(r'[\s,;]+', s)]


def str2bool(value):
if isinstance(value, bool):
return value
value = value.lower()
if value in ('true', 'yes', 't', 'y', '1', 'enable'):
return True
elif value in ('false', 'no', 'f', 'n', '0', 'disable'):
return False
else:
raise argparse.ArgumentTypeError(
f'Boolean value expected: {value} is not a boolean')


def main(cli_args=None):

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -55,23 +71,9 @@ def get_info(function):
get_init_info = get_info(ChatDownloader.__init__)

def add_param(param_type, group, *keys, **kwargs):

is_boolean_flag = kwargs.pop('is_boolean_flag', None)

if is_boolean_flag:
# If True by default, set action to store_false
# If False by default, set action to store_true

default = kwargs.pop('default', None)
kwargs['action'] = 'store_{}'.format(
str(not bool(default)).lower())

info = get_chat_info if param_type == 'chat' else get_init_info
key = keys[0].lstrip('-')
group.add_argument(*keys,
**info[key], # add defaults and help
**kwargs
)
group.add_argument(*keys, **info[key], **kwargs)

def add_chat_param(group, *keys, **kwargs):
add_param('chat', group, *keys, **kwargs)
Expand All @@ -97,7 +99,8 @@ def add_init_param(group, *keys, **kwargs):
'Retry Arguments') # what to do when an error occurs
add_chat_param(retry_group, '--max_attempts', type=int)
add_chat_param(retry_group, '--retry_timeout', type=float)
add_chat_param(retry_group, '--interruptible_retry', is_boolean_flag=True)
add_chat_param(retry_group, '--interruptible_retry',
type=str2bool, nargs='?', const=True)

termination_group = parser.add_argument_group('Termination Arguments')
add_chat_param(termination_group, '--max_messages', type=int)
Expand Down Expand Up @@ -136,8 +139,10 @@ def add_init_param(group, *keys, **kwargs):

output_group = parser.add_argument_group('Output Arguments')
add_chat_param(output_group, '--output', '-o')
add_chat_param(output_group, '--overwrite', is_boolean_flag=True)
add_chat_param(output_group, '--sort_keys', is_boolean_flag=True)
add_chat_param(output_group, '--overwrite',
type=str2bool, nargs='?', const=True)
add_chat_param(output_group, '--sort_keys',
type=str2bool, nargs='?', const=True)
add_chat_param(output_group, '--indent', type=lambda x: int_or_none(x, x))

# Debugging only available from the CLI
Expand Down
2 changes: 1 addition & 1 deletion chat_downloader/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__email__ = 'admin@xenova.com'
__copyright__ = '2020, 2021 xenova'
__url__ = 'https://github.com/xenova/chat-downloader'
__version__ = '0.1.6'
__version__ = '0.1.7'

0 comments on commit 705a7dd

Please sign in to comment.