integrations/twitter: Upgrade to argparse.
This commit is contained in:
parent
3b04b55ffd
commit
18a73324a9
|
@ -26,7 +26,7 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import optparse
|
||||
import argparse
|
||||
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
|
||||
|
||||
import zulip
|
||||
|
@ -40,9 +40,9 @@ def write_config(config, since_id, user):
|
|||
with open(CONFIGFILE, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
parser = optparse.OptionParser(r"""
|
||||
parser = zulip.add_default_arguments(argparse.ArgumentParser(r"""
|
||||
|
||||
%prog --user foo@example.com --api-key 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --twitter-id twitter_handle --site=https://zulip.example.com
|
||||
twitter-bot --user foo@example.com --api-key 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 --twitter-id twitter_handle --site=https://zulip.example.com
|
||||
|
||||
Slurp tweets on your timeline into a specific zulip stream.
|
||||
|
||||
|
@ -72,20 +72,19 @@ parser = optparse.OptionParser(r"""
|
|||
|
||||
Depends on: https://github.com/bear/python-twitter version 3.1
|
||||
(`pip install python-twitter`)
|
||||
""")
|
||||
"""))
|
||||
|
||||
parser.add_option('--twitter-id',
|
||||
help='Twitter username to poll for new tweets from"',
|
||||
metavar='URL')
|
||||
parser.add_option('--stream',
|
||||
help='Default zulip stream to write tweets to')
|
||||
parser.add_option('--limit-tweets',
|
||||
default=15,
|
||||
type='int',
|
||||
help='Maximum number of tweets to push at once')
|
||||
parser.add_argument('--twitter-id',
|
||||
help='Twitter username to poll for new tweets from"',
|
||||
metavar='URL')
|
||||
parser.add_argument('--stream',
|
||||
help='Default zulip stream to write tweets to')
|
||||
parser.add_argument('--limit-tweets',
|
||||
default=15,
|
||||
type=int,
|
||||
help='Maximum number of tweets to push at once')
|
||||
|
||||
parser.add_option_group(zulip.generate_option_group(parser))
|
||||
(options, args) = parser.parse_args()
|
||||
options = parser.parse_args()
|
||||
|
||||
if not options.twitter_id:
|
||||
parser.error('You must specify --twitter-id')
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import optparse
|
||||
import argparse
|
||||
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
|
||||
|
||||
import zulip
|
||||
|
@ -41,9 +41,9 @@ def write_config(config, since_id):
|
|||
with open(CONFIGFILE, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
parser = optparse.OptionParser(r"""
|
||||
parser = zulip.add_default_arguments(argparse.ArgumentParser(r"""
|
||||
|
||||
%prog --user username@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 \
|
||||
twitter-search-bot --user username@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5 \
|
||||
--search="@nprnews,quantum physics"
|
||||
|
||||
Send Twitter search results to a Zulip stream.
|
||||
|
@ -89,24 +89,23 @@ new application under your Twitter account:
|
|||
|
||||
Make sure to go the application you created and click "create my
|
||||
access token" as well. Fill in the values displayed.
|
||||
""")
|
||||
"""))
|
||||
|
||||
parser.add_option('--search',
|
||||
dest='search_terms',
|
||||
help='Terms to search on',
|
||||
action='store')
|
||||
parser.add_option('--stream',
|
||||
dest='stream',
|
||||
help='The stream to which to send tweets',
|
||||
default="twitter",
|
||||
action='store')
|
||||
parser.add_option('--limit-tweets',
|
||||
default=15,
|
||||
type='int',
|
||||
help='Maximum number of tweets to send at once')
|
||||
parser.add_argument('--search',
|
||||
dest='search_terms',
|
||||
help='Terms to search on',
|
||||
action='store')
|
||||
parser.add_argument('--stream',
|
||||
dest='stream',
|
||||
help='The stream to which to send tweets',
|
||||
default="twitter",
|
||||
action='store')
|
||||
parser.add_argument('--limit-tweets',
|
||||
default=15,
|
||||
type=int,
|
||||
help='Maximum number of tweets to send at once')
|
||||
|
||||
parser.add_option_group(zulip.generate_option_group(parser))
|
||||
(opts, args) = parser.parse_args()
|
||||
opts = parser.parse_args()
|
||||
|
||||
if not opts.search_terms:
|
||||
parser.error('You must specify a search term.')
|
||||
|
|
Loading…
Reference in a new issue