Exemplo n.º 1
0
class CommentTest(CompatibilityTestCase):
    def setUp(self):
        fd, self.file_path = mkstemp()
        with open(self.file_path, 'w') as file:
            file.write("# a commented .env file, for testing\n")
            file.write("SOMEVAR='12345' # a var, with an inline comment\n")
            file.write("VAR='giggles'\n")
            file.write("####################\n")
            file.write("\n")
            file.write("# another comment, notice the blank line above\n")
            file.write("    # an indented comment\n")
            file.write("cheese='cake'\n")
            file.write(
                "COMMENT='#comment#test' # a value containing a comment\n")
        self.dotenv = Dotenv(self.file_path)

    def tearDown(self):
        os.unlink(self.file_path)

    def test_create(self):
        self.assertIsInstance(self.dotenv, Dotenv)
        self.assertIsInstance(self.dotenv, dict)

    def test_get_keys(self):
        expected = set(['SOMEVAR', 'VAR', 'cheese', 'COMMENT'])

        self.assertEqual(expected, set(self.dotenv.keys()))

    def test_get_values(self):
        expected = set(['12345', 'giggles', 'cake', '#comment#test'])

        self.assertEqual(expected, set(self.dotenv.values()))
Exemplo n.º 2
0
 def setUp(self):
     env_path = path.join(path.dirname(path.abspath(__file__)), '../.env')
     env = Dotenv(env_path)
     api_key = env.get('FBOPEN_API_KEY')
     
     self.client = fbopen.FBOpen
     self.client.init(api_key)
Exemplo n.º 3
0
class CommentTest(CompatibilityTestCase):
    def setUp(self):
        fd, self.file_path = mkstemp()
        with open(self.file_path, 'w') as file:
            file.write("# a commented .env file, for testing\n")
            file.write("SOMEVAR='12345' # a var, with an inline comment\n")
            file.write("VAR='giggles'\n")
            file.write("####################\n")
            file.write("\n")
            file.write("# another comment, notice the blank line above\n")
            file.write("    # an indented comment\n")
            file.write("cheese='cake'\n")
            file.write("COMMENT='#comment#test' # a value containing a comment\n")
        self.dotenv = Dotenv(self.file_path)

    def tearDown(self):
        os.unlink(self.file_path)

    def test_create(self):
        self.assertIsInstance(self.dotenv, Dotenv)
        self.assertIsInstance(self.dotenv, dict)

    def test_get_keys(self):
        expected = set(['SOMEVAR', 'VAR', 'cheese', 'COMMENT'])

        self.assertEqual(expected, set(self.dotenv.keys()))

    def test_get_values(self):
        expected = set(['12345', 'giggles', 'cake', '#comment#test'])

        self.assertEqual(expected, set(self.dotenv.values()))
Exemplo n.º 4
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("FOO='bar'\n")
         file.write("Bar=foo'\n")
         file.write("baz=1234'\n")
         file.write("url='https://test.oi/do?it=fast'\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 5
0
class DotenvTest(CompatibilityTestCase):
    def setUp(self):
        fd, self.file_path = mkstemp()
        with open(self.file_path, 'w') as file:
            file.write("FOO='bar'\n")
            file.write("Bar=foo'\n")
            file.write("baz=1234'\n")
            file.write("url='https://test.oi/do?it=fast'\n")
        self.dotenv = Dotenv(self.file_path)

    def tearDown(self):
        os.unlink(self.file_path)

    def test_create(self):
        self.assertIsInstance(self.dotenv, Dotenv)
        self.assertIsInstance(self.dotenv, dict)

    def test_get_keys(self):
        expected = set(['FOO', 'Bar', 'baz', 'url'])

        self.assertEqual(expected, set(self.dotenv.keys()))

    def test_get_values(self):
        expected = set(['bar', 'foo', '1234', 'https://test.oi/do?it=fast'])

        self.assertEqual(expected, set(self.dotenv.values()))

    def test_set_new_key_value(self):
        self.dotenv['asd'] = 'qwe'

        newdotenv = Dotenv(self.file_path)

        self.assertIn('asd', newdotenv)
        self.assertEqual('qwe', newdotenv['asd'])

    def test_set_existing_key(self):
        self.dotenv['baz'] = 987

        newdotenv = Dotenv(self.file_path)

        self.assertEqual('987', newdotenv['baz'])
        with open(self.file_path, 'r') as file:
            self.assertEqual(4, len(file.readlines()))

    def test_del_key(self):
        del self.dotenv['baz']

        newdotenv = Dotenv(self.file_path)

        self.assertNotIn('baz', newdotenv)
        with open(self.file_path, 'r') as file:
            self.assertEqual(3, len(file.readlines()))
Exemplo n.º 6
0
class DotenvTest(CompatibilityTestCase):
    def setUp(self):
        fd, self.file_path = mkstemp()
        with open(self.file_path, 'w') as file:
            file.write("FOO='bar'\n")
            file.write("Bar=foo'\n")
            file.write("baz=1234'\n")
            file.write("url='https://test.oi/do?it=fast'\n")
        self.dotenv = Dotenv(self.file_path)

    def tearDown(self):
        os.unlink(self.file_path)

    def test_create(self):
        self.assertIsInstance(self.dotenv, Dotenv)
        self.assertIsInstance(self.dotenv, dict)

    def test_get_keys(self):
        expected = set(['FOO', 'Bar', 'baz', 'url'])

        self.assertEqual(expected, set(self.dotenv.keys()))

    def test_get_values(self):
        expected = set(['bar', 'foo', '1234', 'https://test.oi/do?it=fast'])

        self.assertEqual(expected, set(self.dotenv.values()))

    def test_set_new_key_value(self):
        self.dotenv['asd'] = 'qwe'

        newdotenv = Dotenv(self.file_path)

        self.assertIn('asd', newdotenv)
        self.assertEqual('qwe', newdotenv['asd'])

    def test_set_existing_key(self):
        self.dotenv['baz'] = 987

        newdotenv = Dotenv(self.file_path)

        self.assertEqual('987', newdotenv['baz'])
        with open(self.file_path, 'r') as file:
            self.assertEqual(4, len(file.readlines()))

    def test_del_key(self):
        del self.dotenv['baz']

        newdotenv = Dotenv(self.file_path)

        self.assertNotIn('baz', newdotenv)
        with open(self.file_path, 'r') as file:
            self.assertEqual(3, len(file.readlines()))
Exemplo n.º 7
0
    def __init__(self, sort_key):
        try:
            env = Dotenv('./.env')
            credential_table = env["CREDENTIAL_TABLE_ARN"]
        except IOError:
            try:
                env = Dotenv('../.env')
                credential_table = env["CREDENTIAL_TABLE_ARN"]
            except:
                credential_table = "arn:aws:dynamodb:us-west-2:576309420438:table/dev_credential"

        self.sort_key = sort_key
        self.table_name = credential_table.split('/')[1]
        self.dynamodb = None
Exemplo n.º 8
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("# a commented .env file, for testing\n")
         file.write("SOMEVAR='12345' # a var, with an inline comment\n")
         file.write("VAR='giggles'\n")
         file.write("####################\n")
         file.write("\n")
         file.write("# another comment, notice the blank line above\n")
         file.write("    # an indented comment\n")
         file.write("cheese='cake'\n")
         file.write(
             "COMMENT='#comment#test' # a value containing a comment\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 9
0
 def setAddr(self):
     try:
         cmd_conf = Dotenv('./cmd-conf')
         self.APIaddress = cmd_conf['APIaddress']
         print cmd_conf['APIaddress']
     except IOError:
         env = os.environ
Exemplo n.º 10
0
    def test_set_new_key_value(self):
        self.dotenv['asd'] = 'qwe'

        newdotenv = Dotenv(self.file_path)

        self.assertIn('asd', newdotenv)
        self.assertEqual('qwe', newdotenv['asd'])
Exemplo n.º 11
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("FOO='bar'\n")
         file.write("Bar=foo'\n")
         file.write("baz=1234'\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 12
0
def getadmin():
    import os
    from dotenv import Dotenv
    dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env"))
    os.environ.update(dotenv)
    admin_id = os.environ.get('ADMIN_ID')
    return admin_id
Exemplo n.º 13
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("FOO='bar'\n")
         file.write("Bar=foo'\n")
         file.write("baz=1234'\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 14
0
 def setUp(self):
     try:
         cmd_conf = Dotenv('./cmd-conf')
         self.APIaddress = cmd_conf['APIaddress']
         self.client = Repoclient(self.APIaddress)
     except IOError:
         env = os.environ
Exemplo n.º 15
0
def gettoken():
    import os
    from dotenv import Dotenv
    dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env"))
    os.environ.update(dotenv)
    token = os.environ.get('TOKEN')
    return token
Exemplo n.º 16
0
    def test_del_key(self):
        del self.dotenv['baz']

        newdotenv = Dotenv(self.file_path)

        self.assertNotIn('baz', newdotenv)
        with open(self.file_path, 'r') as file:
            self.assertEqual(3, len(file.readlines()))
Exemplo n.º 17
0
def setting():
	global CONSUMER_KEY
	global CONSUMER_SECRET
	dotenv = Dotenv(join(dirname(__file__),'.env'))
	os.environ.update(dotenv)

	CONSUMER_KEY = os.environ.get('CONSUMER_KEY')
	CONSUMER_SECRET = os.environ.get('CONSUMER_SECRET')
Exemplo n.º 18
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("FOO='bar'\n")
         file.write("Bar=foo'\n")
         file.write("baz=1234'\n")
         file.write("url='https://test.oi/do?it=fast'\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 19
0
    def test_set_existing_key(self):
        self.dotenv['baz'] = 987

        newdotenv = Dotenv(self.file_path)

        self.assertEqual('987', newdotenv['baz'])
        with open(self.file_path, 'r') as file:
            self.assertEqual(4, len(file.readlines()))
Exemplo n.º 20
0
def login():
    from dotenv import Dotenv
    env = request.values.get('env')
    if env == "sandbox":
        dotenv = Dotenv("./environment/.env-sandbox")
    else:
        dotenv = Dotenv("./environment/.env-production")
    os.environ.update(dotenv)
    base_url = os.environ.get('RC_SERVER_URL') + '/restapi/oauth/authorize'
    params = (('response_type', 'code'), ('redirect_uri',
                                          os.environ.get("RC_REDIRECT_URL")),
              ('client_id', os.environ.get("RC_CLIENT_ID")), ('state',
                                                              'initialState'))
    authorize_uri = base_url + '?' + urllib.urlencode(params)
    redirect_uri = os.environ.get('RC_REDIRECT_URL')
    return render_template('login.html',
                           authorize_uri=authorize_uri,
                           redirect_uri=redirect_uri)
Exemplo n.º 21
0
def get_env(var):
    import os
    from dotenv import Dotenv
    dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env"))
    os.environ.update(dotenv)
    gvar = var
    env_var = os.environ. get(gvar)

    return env_var
Exemplo n.º 22
0
    def __init__(self):
        dotenv_path = Dotenv(join(dirname(__file__), '..', '.env'))
        os.environ.update(dotenv_path)

        self.consumer_key = os.environ.get("SALESFORCE_OAUTH_CONSUMER_TOKEN")
        self.consumer_secret = os.environ.get("SALESFORCE_OAUTH_CONSUMER_SECRET")
	self.access_token_url = os.environ.get("SALESFORCE_ACCESS_TOKEN_URL")
        self.username = os.environ.get("SALESFORCE_USER")
        self.password = os.environ.get("SALESFORCE_PASSWORD") 
	self.sf_login = os.environ.get("SALESFORCE_LOGIN")
Exemplo n.º 23
0
 def setUp(self):
     fd, self.file_path = mkstemp()
     with open(self.file_path, 'w') as file:
         file.write("# a commented .env file, for testing\n")
         file.write("SOMEVAR='12345' # a var, with an inline comment\n")
         file.write("VAR='giggles'\n")
         file.write("####################\n")
         file.write("\n")
         file.write("# another comment, notice the blank line above\n")
         file.write("    # an indented comment\n")
         file.write("cheese='cake'\n")
         file.write("COMMENT='#comment#test' # a value containing a comment\n")
     self.dotenv = Dotenv(self.file_path)
Exemplo n.º 24
0
    def __init__(self):
        """
        Initialize Publisher object.
        Twilio SID, authentication token, my phone number
        and the Twilio phone number
        are stored as environment variables on my Pi
        """
        dotenv = Dotenv('.env')
        self.account_sid = dotenv['TWILIO_ACCOUNT_SID']
        self.auth_token = dotenv['TWILIO_AUTH_TOKEN']
        self.my_number = dotenv['MY_DIGITS']
        self.twilio_number = dotenv['TWILIO_DIGITS']

        self.client = Client(self.account_sid, self.auth_token)
Exemplo n.º 25
0
    def __init__(self, customer_id=None, auth_token=None, **kwargs):
        try:
            from dotenv import Dotenv
            dotenv = Dotenv(os.path.join(os.getcwd(), '.env'))
            os.environ.update(dotenv)
        except:
            sys.stderr.write('Skipping load of .env...\n')
            sys.stderr.write(traceback.format_exc())

        if not customer_id:
            customer_id = os.environ['RED_CANARY_CUSTOMER_ID']

        if not auth_token:
            auth_token = os.environ['RED_CANARY_AUTH_TOKEN']

        request_options = dict(params={'auth_token': auth_token})
        request_options.update(kwargs.pop('request_options', None) or {})

        RestClient.__init__(self,
                            'https://%s.my.redcanary.co/openapi/v2' %
                            customer_id,
                            request_options=request_options,
                            **kwargs)
Exemplo n.º 26
0
import json
import os
from confluent_kafka import Producer
import os
from dotenv import Dotenv
configurations = Dotenv('configurations.ini')
os.environ.update(configurations)

from database.controllers.orders import ordersController

controller = ordersController()


class producer:

    kafkaBootstrapServers = os.getenv('kafkaBootstrapServers')
    topics = [os.getenv('notificationTopic'), os.getenv('invoiceTopic')]

    def __init__(self):
        self.producer = Producer(
            {'bootstrap.servers': self.kafkaBootstrapServers})

    def produce(self, count):
        for i in range(0, count):
            orderID = controller.insert()
            for topic in self.topics:
                data = json.dumps({'orderID': orderID}).encode('utf-8')
                self.producer.produce(topic, data)
        self.producer.flush()

Exemplo n.º 27
0
from dotenv import Dotenv
import os

if __name__ == '__main__':

    base_dir = os.path.dirname(os.path.realpath(__file__))
    environment_variables = Dotenv(os.path.join(base_dir, ".env"))
    os.environ.update(environment_variables)

    from dobby_bot import TelegramBot
    TelegramBot(base_dir).start()
Exemplo n.º 28
0
import os
import requests
import json
from dotenv import Dotenv
dotenv = Dotenv("/home/pi/SmartMirror/.env")


# Creates a list of news headlines from news API
def get_news_headlines():
    news_key = os.environ.get('NEWS_API_KEY')
    url = 'http://newsapi.org/v2/top-headlines?country=us'
    params = {'apikey': news_key, 'q': 'cnn'}
    response = requests.get(url, params=params)
    response_json = response.json()  # Convert API output to python dict
    # print(response_json)
    global headlines
    headlines = []
    for i in response_json['articles']:
        headlines.append(i['title'])
    #print(headlines)

    return headlines


# Modify format of headlines
def format_headlines(headlines):
    headlines = headlines
    for i in headlines:
        x = int(len(i) / 2)

    # print(headlines)
Exemplo n.º 29
0
    def test_get_variables(self):
        result = get_variables(self.file_path)

        dotenv = Dotenv(self.file_path)

        self.assertEqual(result, dotenv)
Exemplo n.º 30
0
    parser.add_argument('-o', '--output', default='.')

    parser_unzip = parser.add_mutually_exclusive_group()
    parser_unzip.add_argument('--unzip',
                              '--extract',
                              dest='unzip',
                              action='store_true')
    parser_unzip.add_argument('--no-unzip',
                              '--no-extract',
                              dest='unzip',
                              action='store_false')
    parser.set_defaults(unzip=True)

    args = parser.parse_args()

    dotenv = Dotenv(os.path.join(os.path.dirname(__file__), '.env'))
    nico = NicoOpendata(dotenv)

    list_paths = flatten(nico.list_paths)
    output = os.path.abspath(args.output)

    if args.all:
        paths = list_paths

    if not args.all and args.target:
        paths = select_dict(list_paths, args.target)

    for key, target in paths.items():
        nico.download_file(target,
                           output_dir='{}/{}'.format(output, key),
                           extract=args.unzip)
Exemplo n.º 31
0
# -*- coding:utf-8 -*-
__author__ = 'Widnyana <*****@*****.**>'


from dotenv import Dotenv

if __name__ == '__main__':
    d = Dotenv()
    print d.load()
Exemplo n.º 32
0
# Settings for the Auth0 endpoint
# Default implementation reads the credentials from ~/.auth0.env file
# Alternatively you can also directly set client_domain and client_id
# in this file.

import os

env = None

try:
    from dotenv import Dotenv
    auth0env = os.path.join(os.path.expanduser("~"), '.auth0.env')
    if not os.path.isfile(auth0env):
        auth0env = '/home/uwsgi/.auth0.env'
    env = Dotenv(auth0env)
except (ImportError, IOError):
    env = os.environ

# The following two parameters are mandatory.
client_domain = env["AUTH0_DOMAIN"]
client_id = env["AUTH0_CLIENT_ID"]
debug = env.get("DEBUG", False)

# This is used optionally to decode JWT tokens and avoid double calls to
# Auth0 backedn API to get the user profile.
client_secret = env.get('AUTH0_CLIENT_SECRET', None)

# This will be only necessary if we are going to perform any administrative
# query or task using v2 API
# (currently not suppported)
#client_token = env["AUTH0_TOKEN"]
Exemplo n.º 33
0
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
from os.path import dirname, normpath, join, abspath
from dotenv import Dotenv

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Set up environment
dotenv_path = join(BASE_DIR, '.env')
dotenv = Dotenv(dotenv_path)
os.environ.update(dotenv)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True if os.getenv('DEBUG') == 'true' else False

ALLOWED_HOSTS = ['*']

# Application definition
Exemplo n.º 34
0
    def test_set_new_variable(self):
        set_variable(self.file_path, 'asd', 'qwe')

        dotenv = Dotenv(self.file_path)
        self.assertIn('asd', dotenv)
        self.assertEqual('qwe', dotenv['asd'])
Exemplo n.º 35
0
import os
import time
import re
import logging
from slackclient import SlackClient

from dotenv import Dotenv
# Of course, replace by your correct path
dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env"))
os.environ.update(dotenv)
if os.getenv('SLACK_BOT_TOKEN'):
    slack_client = SlackClient(os.getenv('SLACK_BOT_TOKEN'))
else:
    slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))

# kbot's user ID in Slack: value is assigned after the bot starts up
kbot_id = None

logging.basicConfig(filename='log.log',
                    level=logging.DEBUG,
                    format='%(asctime)s:%(levelname)s:%(message)s')

# constants
RTM_READ_DELAY = 1  # 1 second delay between reading from RTM
PING_COMMAND = "ping"
HELP_COMMAND = "help"
CHOC_COMMAND = "choc"
BOTS_COMMAND = "bots"
# OWNER_COMMAND = "owner"
EXIT_COMMAND = "exit"
MENTION_REGEX = "^<@(|[WU].+?)>(.*)"
Exemplo n.º 36
0
    def test_set_existing_variable(self):
        result = set_variable(self.file_path, 'baz', '987')

        dotenv = Dotenv(self.file_path)
        self.assertIn('baz', dotenv)
        self.assertEqual('987', dotenv['baz'])
Exemplo n.º 37
0
    # check if warming sitemap or google analytics
    if args.id is None and args.sitemap is None:
        print(
            'ERROR! You must either specify a Google Analytics ID'
            ' or a Sitemap.XML file argument to continue.')
        sys.exit(-1)

    # check that .env exits and load variables
    if not os.path.isfile('%s/.env' % PATH):
        print(
            'ERROR! The .env file could not be found in %s\n'
            'Review README.md for more information.') % PATH
        sys.exit(-1)
    else:
        dotenv = Dotenv(os.path.join(PATH, '.env'))
        os.environ.update(dotenv)

    # check that key exists
    if args.id is not None and not os.path.isfile('%s/key.json' % PATH):
        print(
            "ERROR! The key.json file could not be found in %s\n"
            "Review README.md for more information.") % PATH
        sys.exit(-1)

    # add to queue
    def add_to_queue(i, q):
        while True:
            url = q.get()
            crawler.warm_url(url)
            q.task_done()
Exemplo n.º 38
0
# Anthony Krivonos
# server.py
# 07/13/2018

# MARK: - Imports

import os
from os.path import join, dirname
from dotenv import Dotenv

# MARK: - Set .env Path

dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env")) # Of course, replace by your correct path
os.environ.update(dotenv)

# MARK: - Environment Variables

HOST = os.environ.get("HOST")
PORT = int(os.environ.get("PORT"))
BUFFER_SIZE = int(os.environ.get("BUFFER_SIZE"))
MAXIMUM_CONNECTIONS = int(os.environ.get("MAXIMUM_CONNECTIONS"))