From 18a73324a9cd8b71aec77be01e98866c507492bc Mon Sep 17 00:00:00 2001
From: Eeshan Garg <jerryguitarist@gmail.com>
Date: Wed, 2 Aug 2017 00:51:25 -0230
Subject: [PATCH] integrations/twitter: Upgrade to argparse.

---
 zulip/integrations/twitter/twitter-bot        | 29 +++++++--------
 zulip/integrations/twitter/twitter-search-bot | 37 +++++++++----------
 2 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/zulip/integrations/twitter/twitter-bot b/zulip/integrations/twitter/twitter-bot
index e3ae2ae8..9b29a5cc 100755
--- a/zulip/integrations/twitter/twitter-bot
+++ b/zulip/integrations/twitter/twitter-bot
@@ -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')
diff --git a/zulip/integrations/twitter/twitter-search-bot b/zulip/integrations/twitter/twitter-search-bot
index b1f7353e..1ecc4df2 100755
--- a/zulip/integrations/twitter/twitter-search-bot
+++ b/zulip/integrations/twitter/twitter-search-bot
@@ -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.')