twitter/twitter.py: remove proxy related code, we don't need it

This commit is contained in:
Jose Manuel Delicado 2017-01-16 10:46:19 +01:00
parent 0851dc23d8
commit 2370c39c15

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from requests.auth import HTTPProxyAuth
import config import config
import random import random
import BaseHTTPServer import BaseHTTPServer
@ -14,15 +13,7 @@ log = logging.getLogger("sessionTwitter")
class twitter(object): class twitter(object):
def login(self, user_key, user_secret, verify_credentials): def login(self, user_key, user_secret, verify_credentials):
if config.app["proxy"]["server"] != "" and config.app["proxy"]["port"] != "": self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), user_key, user_secret)
args = {"proxies": {"http": "http://{0}:{1}".format(config.app["proxy"]["server"], config.app["proxy"]["port"]),
"https": "https://{0}:{1}".format(config.app["proxy"]["server"], config.app["proxy"]["port"])}}
if config.app["proxy"]["user"] != "" and config.app["proxy"]["password"] != "":
auth = HTTPProxyAuth(config.app["proxy"]["user"], config.app["proxy"]["password"])
args["auth"] = auth
self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), user_key, user_secret, client_args=args)
else:
self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), user_key, user_secret)
if verify_credentials == True: if verify_credentials == True:
self.credentials = self.twitter.verify_credentials() self.credentials = self.twitter.verify_credentials()
@ -30,15 +21,7 @@ class twitter(object):
authorisationHandler.logged = False authorisationHandler.logged = False
port = random.randint(30000, 65535) port = random.randint(30000, 65535)
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', port), authorisationHandler.handler) httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', port), authorisationHandler.handler)
if config.app["proxy"]["server"] != "" and config.app["proxy"]["port"] != "": twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), auth_endpoint='authorize')
args = {"proxies": {"http": "http://{0}:{1}".format(config.app["proxy"]["server"], config.app["proxy"]["port"]),
"https": "https://{0}:{1}".format(config.app["proxy"]["server"], config.app["proxy"]["port"])}}
if config.app["proxy"]["user"] != "" and config.app["proxy"]["password"] != "":
auth = HTTPProxyAuth(config.app["proxy"]["user"], config.app["proxy"]["password"])
args["auth"] = auth
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), auth_endpoint='authorize', client_args=args)
else:
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), auth_endpoint='authorize')
auth = twitter.get_authentication_tokens("http://127.0.0.1:{0}".format(port,)) auth = twitter.get_authentication_tokens("http://127.0.0.1:{0}".format(port,))
webbrowser.open_new_tab(auth['auth_url']) webbrowser.open_new_tab(auth['auth_url'])
while authorisationHandler.logged == False: while authorisationHandler.logged == False: