Ejemplo n.º 1
0
def get_config(env=None):
    if env is None:
        try:
            env = get_environment_variable('ENV')
        except Exception:
            env = 'development'
            print('env is not set, using env:', env)

    return DevelopmentConfig()
Ejemplo n.º 2
0
import sys
import click
import logging
from snapshot_repository import S3Handler
from cassandra_handler import CassandraHandler
from snapshot_metadata import SnapshotMetadata
from utils import (cassandra_backup_to_s3, get_environment_variable, validate_aws_permissions)
from notifier import SlackNotificationSender


# Optional environment variables
HOSTNAME = get_environment_variable('HOSTNAME')
AWS_ACCESS_KEY = get_environment_variable('AWS_ACCESS_KEY_ID')
AWS_SECRET_KEY = get_environment_variable('AWS_SECRET_ACCESS_KEY')
SLACK_TOKEN = get_environment_variable('SLACK_TOKEN')


@click.group()
def cli():
    pass


@click.command()
@click.option('--log-level', default="info")
@click.option('--verbose', is_flag=True)
@click.option('--ssl-no-verify', is_flag=True)
@click.option('--node', default=HOSTNAME)
@click.option('--bucket', required=True)
@click.option('--aws-access-key', default=AWS_ACCESS_KEY)
@click.option('--aws-secret-key', default=AWS_SECRET_KEY)
@click.option('--cassandra-data-dir', default='/var/lib/cassandra/data')
Ejemplo n.º 3
0
import random
import discord
from pymongo import MongoClient
from discord.ext import commands
from utils import get_environment_variable
from .utils import COLOR

buls = 1

MONGO_CONNECTION_STRING = get_environment_variable("MONGO_CONNECTION_STRING")
DB_CLIENT = MongoClient(MONGO_CONNECTION_STRING)
db = DB_CLIENT.get_database('users_db')


class Game(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command(aliases=['diceroll', 'roll'])
    async def dice(self, ctx, amount: int):
        '''dice-guess game'''
        num = amount
        if num <= 6:
            user = ctx.message.author
            server = db[str(user.guild.id)]
            stats = list(server.find({'id': user.id}))
            cred = stats[-1]['credits']
            numtemp = random.randint(1, 6)
            if num == numtemp:
                cred += 50
                newstats = {"$set": {'credits': cred}}
Ejemplo n.º 4
0
# TODO - transfer, casino, etc commands
from itertools import cycle
import discord
from discord.ext import commands, tasks
# Standard modules
# TOKEN, MONGO URI are env-vars
from utils import get_environment_variable
DISCORD_BOT_TOKEN = get_environment_variable("DISCORD_BOT_TOKEN")
# intents (new discord feature to limit bots to certain bucket events)
intents = discord.Intents.default()

# NOTE- The initial version of the bot used TinyDB, but I've migrated to
# MongoDB (still considering sql tho)
# client pointer for API-reference
client = commands.Bot(command_prefix='qq ',
                      case_insensitive=True, intents=intents)
# discord.py has an inbuilt help command, which doesn't look good''
client.remove_command('help')
# status-change-cycle(The bot changes presence after a few mins.)
STATUS = cycle([
    "qq help | :(",
    "with your heart",
    "in tears",
    "with tears",
    "with your soul",
    "I'm so sad",
    "with your tears...",
    "with your feelings",
    "with sparkles"])
ls_cog = ['cogs.fun_cog',
          'cogs.ping_cog',
Ejemplo n.º 5
0
from utils import get_environment_variable

POSTGRES_URI = get_environment_variable('POSTGRES_URI')
POSTGRES_DB = get_environment_variable('POSTGRES_DB')
POSTGRES_USERNAME = get_environment_variable('POSTGRES_USERNAME')
POSTGRES_PASSWORD = get_environment_variable('POSTGRES_PASSWORD')


class Config(object):
    uri_template = 'postgresql://{user}:{password}@{url}/{db}'

    SQLALCHEMY_DATABASE_URI = uri_template.format(user=POSTGRES_USERNAME,
                                                  password=POSTGRES_PASSWORD,
                                                  url=POSTGRES_URI,
                                                  db=POSTGRES_DB)

    SQLALCHEMY_TRACK_MODIFICATIONS = False


class DevelopmentConfig(Config):
    DEBUG = True


def get_config(env=None):
    if env is None:
        try:
            env = get_environment_variable('ENV')
        except Exception:
            env = 'development'
            print('env is not set, using env:', env)
Ejemplo n.º 6
0
def run():
    twitter_handle = get_environment_variable("TWITTER_HANDLE")
    keybase_handle = get_environment_variable("KEYBASE_HANDLE")
    linkedin_username = get_environment_variable("LINKEDIN_USERNAME")
    linkedin_password = get_environment_variable("LINKEDIN_PASSWORD")
    linkedin_profile_handle = get_environment_variable(
        "LINKEDIN_PROFILE_HANDLE")
    github_username = get_environment_variable("GITHUB_USERNAME")
    stackoverflow_handle = get_environment_variable("STACKOVERFLOW_HANDLE")

    result = []
    timestamp = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
    try:
        twitter_followers = get_twitter_followers(twitter_handle)
        result.append({
            "type": "twitter",
            "timestamp": timestamp,
            "twitter_followers": twitter_followers
        })
        keybase_followers = get_keybase_followers(keybase_handle)
        result.append({
            "type": "keybase",
            "timestamp": timestamp,
            "keybase_followers": keybase_followers
        })
        github_followers, github_following = get_github_stats(github_username)
        result.append({
            "type": "github",
            "timestamp": timestamp,
            "github_followers": github_followers,
            "github_following": github_following
        })
        stackoverflow_reputation, stackoverflow_profile_views = get_stackoverflow_followers(
            stackoverflow_handle)
        result.append({
            "type":
            "stackoverflow",
            "timestamp":
            timestamp,
            "stackoverflow_reputation":
            stackoverflow_reputation,
            "stackoverflow_profile_views":
            stackoverflow_profile_views,
        })
        linkedin_profile_views, linkedin_post_views, linkedin_search_appearances = get_linkedin_views(
            linkedin_username, linkedin_password, linkedin_profile_handle)
        result.append({
            "type":
            "linkedin",
            "timestamp":
            timestamp,
            "linkedin_profile_views":
            linkedin_profile_views,
            "linkedin_post_views":
            linkedin_post_views,
            "linkedin_search_appearances":
            linkedin_search_appearances,
        })
    except Exception as e:
        result.append({"timestamp": timestamp, "error": str(e)})
    print(json.dumps(result))
Ejemplo n.º 7
0
from discord.ext import commands, tasks

# Standard modules
# TOKEN, MONGO URI are env-vars
from utils import get_environment_variable
# intents (new discord feature to limit bots to certain bucket events)
intents = discord.Intents.default()

# NOTE- The initial version of the bot used TinyDB, but I've migrated to
# MongoDB (still considering sql tho)
# client pointer for API-reference
client = commands.Bot(command_prefix='qq ',
                      case_insensitive=True,
                      intents=intents)
# Mongo connection string
client.MONGO = get_environment_variable("MONGO_CONNECTION_STRING")
client.TOKEN = get_environment_variable("DISCORD_BOT_TOKEN")

# discord.py has an inbuilt help command, which doesn't look good''
client.remove_command('help')
# status-change-cycle(The bot changes presence after a few mins.)
STATUS = cycle([
    "qq help | :(", "with your heart", "in tears", "with tears",
    "with your soul", "I'm so sad", "with your tears...", "with your feelings",
    "with sparkles"
])
COGS = ['cogs.' + path.split("/")[-1][:-3] for path in glob("./bot/cogs/*.py")]


@client.event
async def on_ready():
Ejemplo n.º 8
0
    # device placement, global seed
    tf.debugging.set_log_device_placement(conf.log.device_placement)
    tf.random.set_seed(conf.general.global_seed)

    # set distribution strategy
    if conf.general.strategy == 'mirrored':
        # del os.environ['TF_CONFIG']
        conf.general.strategy = tf.distribute.MirroredStrategy()
        conf.general.is_chief = True
        conf.general.is_cluster = False
        conf.general.nnodes = 1
    elif conf.general.strategy == 'multimirrored':
        # parse info from $TF_CONFIG, index 0 is chief by definition, chief is also a worker (handling logging etc.)
        conf.general.strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy(
        )
        tf_config = get_environment_variable('TF_CONFIG')
        tf_config = json.loads(tf_config)
        conf.general.nnodes = len(tf_config['cluster']['worker'])
        conf.general.is_chief = tf_config['task']['index'] == 0
        conf.general.is_cluster = True
    elif isinstance(conf.general.strategy, list):
        # del os.environ['TF_CONFIG']
        conf.general.strategy = tf.distribute.MirroredStrategy(
            devices=conf.general.strategy)
        conf.general.is_chief = True
        conf.general.is_cluster = False
        conf.general.nnodes = 1
    else:
        msg = "strategy must be either a device list or one of ['mirrored', 'multimirrored'] but found "
        msg += f"{conf.general.strategy} instead"
        raise RuntimeError(msg)