Skip to main content

This is a set of utilities used by https://Layer7.Solutions for the software tools we create. It includes a logger with default configuration information we setup as well as an oAuth wrapper to be able to pull login information from a custom database.

Project description

What is this?

This is a set of utilities used by https://Layer7.Solutions for the software tools we create. It includes a logger with default configuration information we setup as well as an oAuth wrapper to be able to pull login information from a custom database.

To create the oAuth database, the following creation SQL can be used:

create table oauth_data
(
  username    text not null
    constraint oauth_pkey
      primary key,
  password    text,
  app_id      text,
  app_secret  text,
  app_refresh text,
  agent_of    text
);

How To Build And Install

  1. Be inside the root of the folder
  2. Run python3 setup.py sdist
  3. Run pip install .

How To Use:

Logger:

This creates a custom logger using default file handler, sentry.io integration, and log rotation. A default logspath is set to '/opt/skynet/RedditBots/logs/' however you can override that to your own location. Initialization and configuration.

Note, if using the new sentry_sdk then you need to add the following import and line after the variables but before the creation of the logger. The raven parameter for LoggerConfig() also needs to be set to False.

import sentry_sdk
sentry_sdk.init(dsn=__dsn__, release=__version__)

If you are going to use the legacy Raven then you need to install Raven as a pre-req: pip install raven.

import logging.config
from layer7_utilities import LoggerConfig

__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:
import sentry_sdk
sentry_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

Auth relies on a custom table housing the Reddit application ID, Secret, Username, Password, etc. This is not intended to be setup by anyone else. However if you have access to our database, or are writing a bot that will take advantage, then it can be setup as such.

In the Layer 7 environment the Auth Database Table is 'TheTraveler'.

from layer7_utilities import oAuth

__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)

for account in auth.accounts:
    r = account.login()
    me = r.user.me()
    print('Started Reddit Instance: u/%s' % me)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Layer-7-Utilities-1.3.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

Layer_7_Utilities-1.3.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file Layer-7-Utilities-1.3.0.tar.gz.

File metadata

  • Download URL: Layer-7-Utilities-1.3.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for Layer-7-Utilities-1.3.0.tar.gz
Algorithm Hash digest
SHA256 148459acd1c061400bca863acd9a5e3c93f885d21e4c8a3cae18e56d5408d8af
MD5 036a309eda70a0f50a35c2d9d2e569b6
BLAKE2b-256 49bc25010eb7a3e4ba75733bb09e8e4678cacd5c69624c4735c9780cf5be928a

See more details on using hashes here.

File details

Details for the file Layer_7_Utilities-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: Layer_7_Utilities-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for Layer_7_Utilities-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad30cedeb5d3c85b08dfb5ec73d8ca60d0c3c87b46087a5abe21b30039c6c59b
MD5 5399266217fafa3b39f8b84e62e6e201
BLAKE2b-256 50d6aa70c5d17fb419804609417486dab8e745a85b837d990f6eae03ee71f35d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page