def __init__(self, log_path: Optional[str] = None, log_level: Union[str, int] = logging.DEBUG, log_to_console: bool = True): LoggerManager.init(log_path, level=log_level, with_console=log_to_console) self.logger = LoggerManager.get_logger(__name__)
def __init__(self, dsn_name: str): self.logger = LoggerManager.get_logger(__name__) cnxn = pyodbc.connect('DSN={0}'.format(dsn_name)) # type: Connection cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8') cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8') cnxn.setencoding(encoding='utf-8') self.connection = cnxn
from InstaProfiler.common.LoggerManager import LoggerManager __author__ = 'Sidney' class OAuthException(Exception): def __init__(self, type, msg): super(OAuthException, self).__init__(msg) self.type = type API_URL = "https://api.instagram.com" VERSION = "v1" USERS_ENDPOINT = "users" USER_RECENT_MEDIA = "users/self/media/recent" logger = LoggerManager.get_logger('insta_api') def get_access_token(redirect_url: str, code: str) -> Token: """ :param redirect_url: URL to redirect to :param code: code received from the login :return: Full token """ encoded_url = redirect_url.split("?")[0] data = { "client_id": constants.client_id, "client_secret": constants.client_secret, "grant_type": "authorization_code", "redirect_uri": encoded_url, "code": code }
#-*- encoding: utf-8 -*- from flask import request, jsonify from InstaProfiler.conf import constants from InstaProfiler.conf.flask import app from InstaProfiler import insta_api from InstaProfiler.common.LoggerManager import LoggerManager __author__ = 'Sidney' logger = LoggerManager.get_logger('InstaApp') @app.route('/auth') def auth(): code = request.args.get('code') # redirected from: https://api.instagram.com/oauth/authorize/?client_id=81c816e7c7414edcb82b19a9f40867c1&redirect_uri=http%3A%2F%2Fec2-54-71-98-189.us-west-2.compute.amazonaws.com%3A9000%2Fauth&scope=likes+comments&response_type=code try: token = insta_api.get_access_token(code=code, redirect_url=request.url) token.save() #MongoDao.save_token(token) logger.info("new auth: code: {0}, token: {1}".format( code, token.access_token)) return token.access_token except insta_api.OAuthException as e: return jsonify({"error": e.type, "message": str(e)}) app.run(host=constants.flask_host, port=constants.flask_port)