Skip to content

Commit 18a7332

Browse files
committed
integrations/twitter: Upgrade to argparse.
1 parent 3b04b55 commit 18a7332

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

zulip/integrations/twitter/twitter-bot

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from __future__ import print_function
2727
import os
2828
import sys
29-
import optparse
29+
import argparse
3030
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
3131

3232
import zulip
@@ -40,9 +40,9 @@ def write_config(config, since_id, user):
4040
with open(CONFIGFILE, 'wb') as configfile:
4141
config.write(configfile)
4242

43-
parser = optparse.OptionParser(r"""
43+
parser = zulip.add_default_arguments(argparse.ArgumentParser(r"""
4444
45-
%prog --user [email protected] --api-key 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --twitter-id twitter_handle --site=https://zulip.example.com
45+
twitter-bot --user [email protected] --api-key 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --twitter-id twitter_handle --site=https://zulip.example.com
4646
4747
Slurp tweets on your timeline into a specific zulip stream.
4848
@@ -72,20 +72,19 @@ parser = optparse.OptionParser(r"""
7272
7373
Depends on: https://github.com/bear/python-twitter version 3.1
7474
(`pip install python-twitter`)
75-
""")
76-
77-
parser.add_option('--twitter-id',
78-
help='Twitter username to poll for new tweets from"',
79-
metavar='URL')
80-
parser.add_option('--stream',
81-
help='Default zulip stream to write tweets to')
82-
parser.add_option('--limit-tweets',
83-
default=15,
84-
type='int',
85-
help='Maximum number of tweets to push at once')
86-
87-
parser.add_option_group(zulip.generate_option_group(parser))
88-
(options, args) = parser.parse_args()
75+
"""))
76+
77+
parser.add_argument('--twitter-id',
78+
help='Twitter username to poll for new tweets from"',
79+
metavar='URL')
80+
parser.add_argument('--stream',
81+
help='Default zulip stream to write tweets to')
82+
parser.add_argument('--limit-tweets',
83+
default=15,
84+
type=int,
85+
help='Maximum number of tweets to push at once')
86+
87+
options = parser.parse_args()
8988

9089
if not options.twitter_id:
9190
parser.error('You must specify --twitter-id')

zulip/integrations/twitter/twitter-search-bot

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from __future__ import print_function
2727
import os
2828
import sys
29-
import optparse
29+
import argparse
3030
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
3131

3232
import zulip
@@ -41,9 +41,9 @@ def write_config(config, since_id):
4141
with open(CONFIGFILE, 'wb') as configfile:
4242
config.write(configfile)
4343

44-
parser = optparse.OptionParser(r"""
44+
parser = zulip.add_default_arguments(argparse.ArgumentParser(r"""
4545
46-
%prog --user [email protected] --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 \
46+
twitter-search-bot --user [email protected] --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 \
4747
--search="@nprnews,quantum physics"
4848
4949
Send Twitter search results to a Zulip stream.
@@ -89,24 +89,23 @@ new application under your Twitter account:
8989
9090
Make sure to go the application you created and click "create my
9191
access token" as well. Fill in the values displayed.
92-
""")
93-
94-
parser.add_option('--search',
95-
dest='search_terms',
96-
help='Terms to search on',
97-
action='store')
98-
parser.add_option('--stream',
99-
dest='stream',
100-
help='The stream to which to send tweets',
101-
default="twitter",
102-
action='store')
103-
parser.add_option('--limit-tweets',
104-
default=15,
105-
type='int',
106-
help='Maximum number of tweets to send at once')
107-
108-
parser.add_option_group(zulip.generate_option_group(parser))
109-
(opts, args) = parser.parse_args()
92+
"""))
93+
94+
parser.add_argument('--search',
95+
dest='search_terms',
96+
help='Terms to search on',
97+
action='store')
98+
parser.add_argument('--stream',
99+
dest='stream',
100+
help='The stream to which to send tweets',
101+
default="twitter",
102+
action='store')
103+
parser.add_argument('--limit-tweets',
104+
default=15,
105+
type=int,
106+
help='Maximum number of tweets to send at once')
107+
108+
opts = parser.parse_args()
110109

111110
if not opts.search_terms:
112111
parser.error('You must specify a search term.')

0 commit comments

Comments
 (0)