Conditions | 1 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
18 | def get_parser(self, prog_name): |
||
19 | parser = super(BotsCommand, self).get_parser(prog_name) |
||
20 | |||
21 | bot_parser = parser.add_subparsers( |
||
22 | title='Choose your bot', |
||
23 | description='Use one of these commands to setup and start the ' |
||
24 | 'corresponding bot.', |
||
25 | help='You must choose between one of these subcommands.', |
||
26 | dest='bot_command' |
||
27 | ) |
||
28 | |||
29 | twitter_parser = bot_parser.add_parser( |
||
30 | 'twitter', |
||
31 | description='Starts the Twitter bot.', |
||
32 | help="Use this command to start and customize the Twitter bot." |
||
33 | "For this command to work, you have to specify the path to " |
||
34 | "the file containing your Twitter API credentials using the " |
||
35 | "-c (or --credentials-file) argument. For more details about " |
||
36 | "the Twitter API credentials file format, please refer to the " |
||
37 | "following command: 'gearbox bots twitter -h'." |
||
38 | ) |
||
39 | twitter_parser.add_argument( |
||
40 | '-n', '--number-of-tweets', type=int, |
||
41 | dest='number_of_tweets', default=TwitterBot.MAX_TWEETS_TO_PUSH, |
||
42 | help='Sets a custom number of tweets to push on twitter, instead ' |
||
43 | 'of default: %s. Beware though, your value cannot be bigger ' |
||
44 | 'than the default one, only smaller.' |
||
45 | % TwitterBot.MAX_TWEETS_TO_PUSH |
||
46 | ) |
||
47 | twitter_parser.add_argument( |
||
48 | '-cf', '--credentials-file', type=str, |
||
49 | dest='twitter_credentials_file', required=True, |
||
50 | help="This file must contain the your Twitter API " |
||
51 | "credentials in the following json format: " |
||
52 | "{" |
||
53 | "'consumer_key':'YOUR_CONSUMER_KEY', " |
||
54 | "'consumer_secret':'YOUR_CONSUMER_SECRET', " |
||
55 | "'access_token_key':'YOUR_ACCESS_TOKEN_KEY', " |
||
56 | "'access_token_secret':'YOUR_ACCESS_TOKEN_SECRET'" |
||
57 | "} " |
||
58 | "Each element of this file must be on a separate line, and " |
||
59 | "each line must end with an \\n character." |
||
60 | ) |
||
61 | |||
62 | # TODO: Fix broken help display (gearbox bots twitter -h displays the |
||
63 | # TODO: same help message as gearbox bots, which shouldn't be the case) |
||
64 | |||
65 | bot_parser.add_parser('github', |
||
66 | description='Starts the Github bot.', |
||
67 | help='Starts the Github bot.') |
||
68 | |||
69 | return parser |
||
70 | |||
126 |