mypy: Annotate api/integrations/twitter/twitter-search-bot
This commit is contained in:
parent
3f8f4dc616
commit
1010927188
|
@ -27,13 +27,14 @@ from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import optparse
|
import optparse
|
||||||
import six.moves.configparser
|
from six.moves.configparser import ConfigParser, NoSectionError, NoOptionError
|
||||||
|
|
||||||
import zulip
|
import zulip
|
||||||
VERSION = "0.9"
|
VERSION = "0.9"
|
||||||
CONFIGFILE = os.path.expanduser("~/.zulip_twitterrc")
|
CONFIGFILE = os.path.expanduser("~/.zulip_twitterrc")
|
||||||
|
|
||||||
def write_config(config, since_id):
|
def write_config(config, since_id):
|
||||||
|
# type: (ConfigParser, int) -> None
|
||||||
if 'search' not in config.sections():
|
if 'search' not in config.sections():
|
||||||
config.add_section('search')
|
config.add_section('search')
|
||||||
config.set('search', 'since_id', since_id)
|
config.set('search', 'since_id', since_id)
|
||||||
|
@ -111,14 +112,14 @@ if not opts.search_terms:
|
||||||
parser.error('You must specify a search term.')
|
parser.error('You must specify a search term.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = six.moves.configparser.ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(CONFIGFILE)
|
config.read(CONFIGFILE)
|
||||||
|
|
||||||
consumer_key = config.get('twitter', 'consumer_key')
|
consumer_key = config.get('twitter', 'consumer_key')
|
||||||
consumer_secret = config.get('twitter', 'consumer_secret')
|
consumer_secret = config.get('twitter', 'consumer_secret')
|
||||||
access_token_key = config.get('twitter', 'access_token_key')
|
access_token_key = config.get('twitter', 'access_token_key')
|
||||||
access_token_secret = config.get('twitter', 'access_token_secret')
|
access_token_secret = config.get('twitter', 'access_token_secret')
|
||||||
except (six.moves.configparser.NoSectionError, six.moves.configparser.NoOptionError):
|
except (NoSectionError, NoOptionError):
|
||||||
parser.error("Please provide a ~/.zulip_twitterrc")
|
parser.error("Please provide a ~/.zulip_twitterrc")
|
||||||
|
|
||||||
if not (consumer_key and consumer_secret and access_token_key and access_token_secret):
|
if not (consumer_key and consumer_secret and access_token_key and access_token_secret):
|
||||||
|
@ -126,7 +127,7 @@ if not (consumer_key and consumer_secret and access_token_key and access_token_s
|
||||||
|
|
||||||
try:
|
try:
|
||||||
since_id = config.getint('search', 'since_id')
|
since_id = config.getint('search', 'since_id')
|
||||||
except (six.moves.configparser.NoOptionError, six.moves.configparser.NoSectionError):
|
except (NoOptionError, NoSectionError):
|
||||||
since_id = 0
|
since_id = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue