1

I've read the documentation but still can't figure out how to achieve the following behavior: 1.likes. Give a specified number of likes to users in a tinder (in the future, this may contain more options, such as "gender", "frequency", "age", etc.) 2. Write a given text to a given number of people on tinder (in the future, there may also be more options).

There is my code:

parser = argparse.ArgumentParser(description='Badoo liker', epilog='Enjoy the program! :)')
# I also tried "add_mutually_exclusive_group" instead of "add_argument_group"
chat_args = parser.add_argument_group(title='chat_args')
chat_args.add_argument('-c', '--chat', help='chat help')
chat_args.add_argument('-t', '--text', help='text help')
chat_args.add_argument('-n', '--number', help='n help')

like_args = parser.add_argument_group(title='like_args')
like_args.add_argument('-l', '--like', help='like help')
like_args.add_argument('-n', '--number', help='n help')

args = parser.parse_args()

Usage:
$script.py chat --text 'Hello world' -n 20 # Var 1
$script.py liking -n 20 # Var 2

Obviously, I'm waiting for arguments either for a chat or either for liking

P.S. I'm getting an error because of -n common argument, but even if comment it it will not working as expecting

Progman
  • 16,827
  • 6
  • 33
  • 48
salius
  • 918
  • 1
  • 14
  • 30

2 Answers2

1

It's a little hard to tell what you understand and what has worked or not for you.

This is more of a comment, but long enough that I'll make it answer.

Are those usage lines samples of what you use when calling this script? What error(s) do you get?

Have you tried scipt.py -h to see the help?

I don't see a positional argument that would accept a string like "chat" or "liking". I suspect you want to use the subcommands mechanism, but get the basic argparse working.

I often suggest including a print(args) line to get a clear idea of what the parser has done. Though obviously you won't see that while argparse is raising errors.

Postpone the use of groups until you get the basics down. argument_group just groups arguments in the help display. mutually_exclusive_group is a parsing tool, that complains if you try to use more than one item in the group.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
0

Eventually, I did it, the next code is (apparently) meets my question

# "metavar=''" -just hide redundant double --key KEY word
parser = argparse.ArgumentParser(description='Badoo liker', epilog='Enjoy the program! :)')
subparsers = parser.add_subparsers(help='')

parser_like = subparsers.add_parser('like', help='like help')
parser_like.add_argument('-n', '--number', metavar='', help='Set count of likes', default=49)
parser_like.add_argument('-f', '--frequency', metavar='', help='Set chance to like/dislike', default=70)

parser_chat = subparsers.add_parser('chat', help='chat help')
parser_chat.add_argument('-n', '--number', metavar='', help='number help', required=True)
parser_chat.add_argument('-t', '--text', metavar='', help='text help', required=True)

args = parser.parse_args()
salius
  • 918
  • 1
  • 14
  • 30