import sys
# Library compatibility
-# StringIO module
-try:
- from StringIO import StringIO, BytesIO
-except:
- from io import StringIO, BytesIO
-
-# HTMLParser module
if sys.version[0] == "2":
from HTMLParser import HTMLParser
+ from urllib2 import URLError
else:
from html.parser import HTMLParser
+ from urllib.error import URLError
+
unescape = HTMLParser().unescape
# According to https://github.com/python/cpython/blob/master/Lib/html/parser.py#L547 ,
# in python 3.5 maybe I should use
import socks
import socket
+from io import BytesIO
from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
from twitter.api import *
from twitter.oauth import OAuth, read_token_file
from twitter.oauth_dance import oauth_dance
from twitter.util import printNicely
-from urllib import error
-
from .draw import *
from .colors import *
from .config import *
return parser.parse_args()
+def proxy_connect(args):
+ """
+ Connect to specified proxy
+ """
+ if args.proxy_host:
+ # Setup proxy by monkeypatching the standard lib
+ if args.proxy_type.lower() == "socks5" or not args.proxy_type:
+ socks.set_default_proxy(
+ socks.SOCKS5, args.proxy_host,
+ int(args.proxy_port))
+ elif args.proxy_type.lower() == "http":
+ socks.set_default_proxy(
+ socks.HTTP, args.proxy_host,
+ int(args.proxy_port))
+ elif args.proxy_type.lower() == "socks4":
+ socks.set_default_proxy(
+ socks.SOCKS4, args.proxy_host,
+ int(args.proxy_port))
+ else:
+ printNicely(
+ magenta("Sorry, wrong proxy type specified! Aborting..."))
+ sys.exit()
+ socket.socket = socks.socksocket
+
+
def authen():
"""
Authenticate with Twitter OAuth
# Initial
args = parse_arguments()
try:
- if args.proxy_host:
- # Setup proxy by monkeypatching the standard lib
- # You might want to check https://github.com/Anorov/PySocks for further
- # further info.
- if args.proxy_type.lower() == "socks5" or not args.proxy_type:
- socks.set_default_proxy(socks.SOCKS5, args.proxy_host, int(args.proxy_port))
- elif args.proxy_type.lower() == "http":
- socks.set_default_proxy(socks.HTTP, args.proxy_host, int(args.proxy_port))
- elif args.proxy_type.lower() == "socks4":
- socks.set_default_proxy(socks.SOCKS4, args.proxy_host, int(args.proxy_port))
- else:
- printNicely(magenta("Sorry, wrong proxy type specified! Aborting..."))
- sys.exit()
- socket.socket = socks.socksocket
+ proxy_connect(args)
init(args)
+ # Twitter API connection problem
except TwitterHTTPError:
printNicely('')
printNicely(
printNicely(magenta("Let's try again later."))
save_history()
sys.exit()
- except (ConnectionRefusedError, socks.ProxyConnectionError, error.URLError):
+ # Proxy connection problem
+ except (socks.ProxyConnectionError, URLError):
printNicely(
magenta("There seems to be a connection problem."))
printNicely(