这是https://layer7.solutions为我们创建的软件工具使用的一组实用程序。它包括一个带有我们设置的默认配置信息的记录器,以及一个能够从自定义数据库中提取登录信息的oauth包装器。

Layer-7-Utilities的Python项目详细描述


这是什么?

这是https://Layer7.Solutions为我们创建的软件工具使用的一组实用程序它包括一个带有我们设置的默认配置信息的记录器,以及一个能够从自定义数据库中提取登录信息的oauth包装器。

要创建oauth数据库,可以使用以下创建sql:

createtableoauth_data(usernametextnotnullconstraintoauth_pkeyprimarykey,passwordtext,app_idtext,app_secrettext,app_refreshtext,agent_oftext);

如何构建和安装

  1. 在文件夹的根目录中
  2. 运行python3 setup.py sdist
  3. 运行pip install .

使用方法:

记录器:

这将使用默认文件处理程序sentry.io集成和日志旋转创建自定义日志记录器。默认logspath设置为“/opt/skynet/redditbots/logs/”,但是您可以将其覆盖到自己的位置。 初始化和配置

注意,如果使用新的sentry_sdk,则需要在变量之后但在创建记录器之前添加以下导入和行。LoggerConfig()raven参数也需要设置为false。

importsentry_sdksentry_sdk.init(dsn=__dsn__,release=__version__)

如果要使用传统raven,则需要将raven安装为一个前置请求:pip install raven

importlogging.configfromlayer7_utilitiesimportLoggerConfig__botname__='Short_Name_For_The_Bot'__description__='Description of the bot'__author__='Authors Name/Info'__version__='1.2.3'__dsn__='Get from Sentry.io'# Sets up the sentry_sdk integration:importsentry_sdksentry_sdk.init(dsn=__dsn__,release=__version__)# Create the logger (with Raven (legacy) disabled)logspath='Path/To/The/Logs/Folder/'# With trailing backslash.loggerconfig=LoggerConfig(__dsn__,__botname__,__version__,logspath,raven=False)logging.config.dictConfig(loggerconfig.get_config())logger=logging.getLogger('root')logger.info(u"/*********Starting App*********\\")logger.info(u"App Name: {} | Version: {}".format(__botname__,__version__))

认证

auth依赖于一个包含reddit应用程序id、secret、username、password等的自定义表。其他任何人都不会设置这个表。但是,如果您有权访问我们的数据库,或者正在编写一个可以利用的bot,那么就可以这样设置它。

在第7层环境中,auth数据库表是“thetraveler”。

fromlayer7_utilitiesimportoAuth__botname__='Short_Name_For_The_Bot'__description__='Description of the bot'__author__='Authors Name/Info'__version__='1.2.3'__dsn__='Get from Sentry.io'__agent_of__='category value'auth=oAuth()auth.get_accounts(__agent_of__,__description__,__version__,__author__,__botname__,DB_USERNAME,DB_PASSWORD,DB_HOST,DatabaseTableName)foraccountinauth.accounts:r=account.login()me=r.user.me()print('Started Reddit Instance: u/%s'%me)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JavaFX 11可编辑组合框引发IndexOutOfBoundsException   java选择数组中的数组元素   java我从来没有找到创建2D ArrayList的正确方法   java JPA查找orderById的顶部数据,并按字符串过滤Id   使用java在ejabberd中进行xmpp外部身份验证   从ajax调用向java传递点运算符   java如何使用ReadWriteLock   使用Spring控制器和jQueryAjax的java重定向   java使JFrame中的JPanel可滚动   java如何用多个。jar库?   java EditText在RecyclerView中失去了对滚动的关注   java为什么我们必须扩展Servlet或GenericServlet或HttpServlet来创建Servlet应用程序?如果不扩展,我们可以开发Servlet应用程序吗?   使用递归java查找数组中的最大值   具有不同字段数的html表单的java域传输对象   java文本视图扩展;不支持操作异常   java如何使用iText的HTMLWorker类将多语言HTML字符串呈现为PDF