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
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 setAddr(self): try: cmd_conf = Dotenv('./cmd-conf') self.APIaddress = cmd_conf['APIaddress'] print cmd_conf['APIaddress'] except IOError: env = os.environ
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)
def setUp(self): try: cmd_conf = Dotenv('./cmd-conf') self.APIaddress = cmd_conf['APIaddress'] self.client = Repoclient(self.APIaddress) except IOError: env = os.environ
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
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
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')
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 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 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()))
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)
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
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")
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 __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)
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)
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()
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
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)
# 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"))
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'])
def test_get_variables(self): result = get_variables(self.file_path) dotenv = Dotenv(self.file_path) self.assertEqual(result, dotenv)
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'])
import os from dotenv import Dotenv try: dotenv_ = Dotenv('/Users/localuser/.env') os.environ.update(dotenv_) except IOError: pass DATABASES = { "lendi_ai": { "host": os.getenv("LENDIAI_DBHOST"), "database": os.getenv("LENDIAI_DATABASE"), "user": os.getenv("LENDIAI_DBUSER"), "password": os.getenv("LENDIAI_DBPASSWORD") }, "salesforce": { "host": os.getenv("SF_DBHOST"), "database": os.getenv("SF_DATABASE"), "user": os.getenv("SF_DBUSER"), "password": os.getenv("SF_DBPASSWORD"), "ssl": True } } XTRACTA_URL_TIMEOUT = 86400 XTRACTA = {"url": os.getenv("XTRACTA_URL"), "key": os.getenv("XTRACTA_KEY")} WORKFLOW_MAPPING = {"a1u6F000003HtqHQAS": "50713"}
from votr import votr, db, celery from multiprocessing import Process import requests import os import time from tasks import close_poll import jwt import config # Load env file from dotenv import Dotenv try: env = Dotenv('.env') except IOError: env = os.environ # helper to generate JWT's def generate_token(payload): token = jwt.encode(payload, env[config.AUTH0_CLIENT_SECRET], algorithm='HS256').decode() return token class Testvotr(): @classmethod def setUpClass(cls): votr.config['DEBUG'] = False votr.config['TESTING'] = True
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].+?)>(.*)"
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()
# 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()
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)