def _open(self): """ Initialize EsiPy :return: """ config = key_config.load(self.config_file, self.CONFIG_REQUIREMENTS) self.esi_app = App.create(config['swagger_spec_url']) mc = memcache.Client(['127.0.0.1:11211'], debug=0) cache = MemcachedCache(memcache_client=mc) # init the security object ''' esisecurity = EsiSecurity( app=esiapp, redirect_uri=config.ESI_CALLBACK, client_id=config.ESI_CLIENT_ID, secret_key=config.ESI_SECRET_KEY, ) ''' # init the client self.esi_client = EsiClient( # security=esisecurity, cache=cache, headers={'User-Agent': config['esi_user_agent']})
def get_api(fn, scopes): esi_app = App.create( 'https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility') esi_security = EsiSecurity( app=esi_app, redirect_uri='http://localhost:8080/callback', client_id='0b9ac4978a9a4feba20a7eba4f666a46', secret_key='odtDKZWZbwbFnBHNXnOhRX50YrU49owBw1qE3v7p', ) esi_client = EsiClient(retry_requests=True, security=esi_security) def write_refresh_token(refresh_token, **kwargs): with open(fn, "w") as f: f.write(refresh_token) AFTER_TOKEN_REFRESH.add_receiver(write_refresh_token) if os.path.isfile(fn): with open(fn) as f: token = open(fn).read() esi_security.update_token({ 'access_token': '', 'expires_in': -1, 'refresh_token': token }) tokens = esi_security.refresh() else: print(esi_security.get_auth_uri(scopes=scopes)) tokens = esi_security.auth(input()) write_refresh_token(**tokens) api_info = esi_security.verify() return api_info, esi_app, esi_client
def __init__(self, token, refresh=False): self.client_id = os.environ.get('EVE_SKILLS_CID') self.secret_id = os.environ.get('EVE_SKILLS_SECRET') self.redir_url = os.environ.get('EVE_SKILLS_REDIR') self.app = App.create( url= "https://esi.evetech.net/latest/swagger.json?datasource=tranquility" ) self.security = EsiSecurity( app=self.app, redirect_uri=self.redir_url, client_id=self.client_id, secret_key=self.secret_id, ) self.client = EsiClient( header={'User-Agent': 'EVE-SKILLS'}, raw_body_only= False, # parse json automatically, slow, bad performance security=self.security) self.token = None if not refresh: self.token = self.security.auth( token) # use code from login redirect if refresh: print('[I] refreshing token') self.security.update_token({ 'access_token': '', 'expires_in': -1, # force refresh anyway 'refresh_token': token }) self.token = self.security.refresh() print(self.token)
def get(release='latest',source='tranquility'): """ Lets try ESIpy instead of bravado... """ global __external_clients__ existing = __external_clients__.get('ESIPYAPP',__mk_key__(release,source)) if existing is None: this_url = "https://esi.tech.ccp.is/%s/swagger.json?datasource=%s" % (release, source) print(this_url) existing = App.create(url=this_url) __external_clients__.set('ESIPYAPP',__mk_key__(release,source),existing) return existing
def setUp(self, urlopen_mock): # I hate those mock... thx urlopen instead of requests... urlopen_mock.return_value = open('test/resources/swagger.json') self.app = App.create('https://esi.tech.ccp.is/latest/swagger.json') self.security = EsiSecurity( app=self.app, redirect_uri=TestEsiSecurity.CALLBACK_URI, client_id=TestEsiSecurity.CLIENT_ID, secret_key=TestEsiSecurity.SECRET_KEY, )
def init_esi(): esi_app = App.create('https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility') esi_security = EsiSecurity( app=esi_app, redirect_uri='https://www.msully.net/stuff/get-token', client_id='fca36d677f9a4b8e8581d8cd2c738c2c', # 'The "Secret Key" should never be human-readable in your application.' secret_key=codecs.decode('AIUr5ntWiEIXiavPjKtUCiNFwlvTBlJqmElgAk4x', 'rot_13'), ) esi_client = EsiClient(esi_security) return ESI(esi_app, esi_security, esi_client)
def init_esi(): esi_app = App.create( 'https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility') esi_security = EsiSecurity( app=esi_app, redirect_uri='https://www.msully.net/stuff/get-token', client_id='fca36d677f9a4b8e8581d8cd2c738c2c', # 'The "Secret Key" should never be human-readable in your application.' secret_key=codecs.decode('AIUr5ntWiEIXiavPjKtUCiNFwlvTBlJqmElgAk4x', 'rot_13'), ) esi_client = EsiClient(esi_security) return ESI(esi_app, esi_security, esi_client)
def setUp(self, urlopen_mock): # I hate those mock... thx urlopen instead of requests... urlopen_mock.return_value = open('test/resources/swagger.json') warnings.simplefilter('ignore') self.app = App.create( 'https://esi.evetech.net/latest/swagger.json' ) self.security = EsiSecurity( app=self.app, redirect_uri=TestEsiPy.CALLBACK_URI, client_id=TestEsiPy.CLIENT_ID, secret_key=TestEsiPy.SECRET_KEY, ) self.cache = DictCache() self.client = EsiClient(self.security, cache=self.cache) self.client_no_auth = EsiClient(cache=self.cache, retry_requests=True)
def setUp(self, urlopen_mock): # I hate those mock... thx urlopen instead of requests... urlopen_mock.return_value = open('test/resources/swagger.json') warnings.simplefilter('ignore') self.app = App.create('https://esi.evetech.net/latest/swagger.json') with open(TestEsiPy.RSC_SSO_ENDPOINTS, 'r') as sso_endpoints: with open(TestEsiPy.RSC_JWKS, "r") as jwks: self.security = EsiSecurity( app=self.app, redirect_uri=TestEsiPy.CALLBACK_URI, client_id=TestEsiPy.CLIENT_ID, secret_key=TestEsiPy.SECRET_KEY, sso_endpoints=json.load(sso_endpoints), jwks_key=json.load(jwks)) self.cache = DictCache() self.client = EsiClient(self.security, cache=self.cache) self.client_no_auth = EsiClient(cache=self.cache, retry_requests=True)
def main(configpath="."): global sc, swagger, esi config.read("%s/config.ini" % configpath) searches.read("%s/searches.ini" % configpath) sc = SlackClient(config.get('slack', 'slack_api_token')) swagger = App.create(url="https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility") esi = EsiClient( retry_requests=True, # set to retry on http 5xx error (default False) header={'User-Agent': 'Killmail Slack Bot by Prozn https://github.com/prozn/dankbot/'} ) while True: if getRedisq(): time.sleep(0.5) else: time.sleep(5)
def authenticate(): app = App.create( url="https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility" ) security = EsiSecurity( app=app, redirect_uri='http://localhost:51350', client_id=secret['client_id'], secret_key=secret['secret_key'], ) client = EsiClient(retry_requests=True, header={'User-Agent': 'shipLocation'}, security=security) eve_sso_auth_url = security.get_auth_uri( scopes=['esi-location.read_ship_type.v1']) webbrowser.open(eve_sso_auth_url, new=2) # open in a new browser tab auth_code = fetch_auth_code( ) # fetch authentication code using a temporary web server tokens = security.auth(auth_code) return (app, client, security, tokens)
def __init__(self): self.db = Database() self.config = Config() self.scopes = self.config.getConfig()["settings"]["esiScopes"] self.esi_app = App.create( url=self.config.getConfig()["settings"]["esiURL"], ) self.security = EsiSecurity( app=self.esi_app, redirect_uri=self.config.getConfig()["settings"]["esiCallback"], client_id=self.config.getConfig()["settings"]["esiClientID"], secret_key=self.config.getConfig()["settings"]["esiSecretKey"], headers={ 'User-Agent': self.config.getConfig()["settings"]["esiCustomHeader"] }) self.client = EsiClient( security=self.security, retry_requests=True, headers={ 'User-Agent': self.config.getConfig()["settings"]["esiCustomHeader"] })
def main(self): print "setting up the app..." self.app = App.create( url= "https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility" ) print "done. \n Setting up the client." self.client = EsiClient( retry_requests= True, # set to retry on http 5xx error (default False) header={'User-Agent': 'Jimmy - api test app: [email protected]'}, raw_body_only= True, # default False, set to True to never parse response and only return raw JSON string content. ) print "done, after this it's all me and my calls." chars = ["alderith", "gruxella", "lord grapefruit", "druzidelcastro"] try: # self.get_id_for_users(chars) # self.get_group_item_ids() self.get_orders_for_region(10000002) except Exception as err: self.pp.pprint(err)
import logging from flask import Flask, render_template, request, flash, redirect, url_for from esipy import App, EsiClient, EsiSecurity from lib import CharacterExplorer, all_esi_read_scopes app = Flask(__name__) app.config.from_json('config.json') esi_headers = {'User-Agent': 'EVE Character Explorer | [email protected]'} esi_app = App.create( 'https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility') esi_security = EsiSecurity(app=esi_app, client_id=app.config['CLIENT_ID'], secret_key=app.config['SECRET_KEY'], redirect_uri=app.config['REDIRECT_URI'], headers=esi_headers) esi_client = EsiClient(security=esi_security, headers=esi_headers) @app.route('/') def index(): return render_template( 'index.html', sso_go=esi_security.get_auth_uri(scopes=all_esi_read_scopes)) @app.route('/view', methods=['POST']) def view(): token = request.form.get('refresh_token')
# 4) Wait a couple of seconds for the browser to open import webbrowser from esipy import App from esipy import EsiClient from esipy import EsiSecurity from flask import Flask, request CLIENT_ID = '' SECRET_KEY = '' SCOPES = ['esi-universe.read_structures.v1', 'esi-markets.structure_markets.v1'] app = Flask(__name__) esi_app = App.create(url="https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility") security = EsiSecurity( app=esi_app, redirect_uri='http://127.0.0.1:5000/ESICallback', client_id=CLIENT_ID, secret_key=SECRET_KEY ) client = EsiClient( retry_requests=True, header={'User-Agent': 'ESI Token Fetcher'}, security=security ) webbrowser.open_new(security.get_auth_uri(scopes=SCOPES))
import webbrowser from esipy import App from esipy import EsiClient from esipy import EsiSecurity from flask import Flask, request CLIENT_ID = '' SECRET_KEY = '' SCOPES = [ 'esi-universe.read_structures.v1', 'esi-markets.structure_markets.v1' ] app = Flask(__name__) esi_app = App.create( url="https://esi.evetech.net/latest/swagger.json?datasource=tranquility") security = EsiSecurity(app=esi_app, redirect_uri='http://127.0.0.1:5000/ESICallback', headers={'User-Agent': 'ESI Token Fetcher'}, client_id=CLIENT_ID, secret_key=SECRET_KEY) client = EsiClient(retry_requests=True, headers={'User-Agent': 'ESI Token Fetcher'}, security=security) state = ''.join(random.choices(string.ascii_letters + string.digits, k=32)) webbrowser.open_new(security.get_auth_uri(scopes=SCOPES, state=state))
app = Flask(__name__) app.register_blueprint(main, url_prefix='/') app.register_blueprint(eve, url_prefix='/eve') ## CONFIG app.config['SQL_USER'] = "******" app.config['SQL_PASSWORD'] = "******" app.config['ESI_CLIENT_ID'] = "d9e042c7462046018b867637ba6fe1cd" app.config['ESI_SECRET_KEY'] = "fEL01TRwKRZKGsW48bnpNm3TInKcK7o5hmjsW7vS" app.config['ESI_CALLBACK_URL'] = "http://127.0.0.1:5000/eve/callback" app.config['CORPORATION_ID'] = 98538579 ## ESI from esipy import App as esiapp from esipy import EsiClient, EsiSecurity esi_app = esiapp.create( url="https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility") esi_security = EsiSecurity( app=esi_app, redirect_uri=app.config['ESI_CALLBACK_URL'], client_id=app.config['ESI_CLIENT_ID'], secret_key=app.config['ESI_SECRET_KEY'], ) esi_client = EsiClient( retry_requests=True, header={ 'User-Agent': 'Something CCP can use to contact you and that define your app' }, raw_body_only=False, security=esi_security) app.config['ESI_REDIRECT_URL'] = esi_security.get_auth_uri(
from esipy import App, EsiClient, EsiSecurity from esipy.exceptions import APIException from .settings import ESI_URL, ESI_CONNECT_IMG_BAR, ESI_CLIENT_ID, ESI_SECRET_KEY, ESI_CALLBACK_URL, ESI_SCOPES esi_app = App.create(ESI_URL) esi_security = EsiSecurity(app=esi_app, redirect_uri=ESI_CALLBACK_URL, client_id=ESI_CLIENT_ID, secret_key=ESI_SECRET_KEY) esi_client = EsiClient(security=esi_security) esi_scopes = ESI_SCOPES esi_secure = esi_security.get_auth_uri(scopes=esi_scopes) esi_secure_url = "<a href='" + esi_secure + "'><img src='" + ESI_CONNECT_IMG_BAR + "'></a>" def esi_update_token(request): esi_security.update_token(request.session['token']) def esi_refresh_verify(request): esi_security.update_token(request.session['token']) esi_security.refresh() return esi_security.verify() def esi_verify(): return esi_security.verify()
import json from esipy import App, EsiClient from esipy.cache import FileCache from esipy.exceptions import APIException import config esiapp = App.create(config.ESI_SWAGGER_JSON) esiclient = EsiClient( # cache=RedisCache(Redis(config.REDIS_CACHE_HOST, port=config.REDIS_CACHE_PORT)), cache=FileCache('.webcache'), headers={'User-Agent': config.ESI_USER_AGENT}) def _get_esi(op, raw_body_only=False): """ Try to get a result from an esipy request response tuple :param op: Request response tuple generated by esiapp.op :return: parsed result data :raises: `esipy.excpetions.APIException` if an ESI Exception is encountered """ res = esiclient.request(op, raw_body_only=raw_body_only) if res.status == 200: if raw_body_only: return json.loads(res.raw.decode('utf-8')) else: return res.data else:
''' Created on May 12, 2017 @author: Aradina ''' from design import Ui_MainWindow from esipy import EsiClient, App from json import loads from sys import argv from PyQt5.QtWidgets import QMessageBox, QApplication, QMainWindow, QTableWidgetItem from PyQt5.QtGui import QPixmap from urllib import request from datetime import datetime esiApp = App.create( 'https://esi.evetech.net/latest/swagger.json?datasource=tranquility' ) # this establishes the ESI connection. esi_client = EsiClient() class eitMain(QMainWindow): def __init__(self): super(eitMain, self).__init__() self.ui = Ui_MainWindow() #Opens the main window. self.ui.setupUi(self) self.ui.searchBtn.clicked.connect( self.charSearch) #this is the search button. self.ui.actionExit.triggered.connect( QApplication.quit) #This is the quit option in the menu bar.