Skip to content
Permalink
Browse files
global config module
  • Loading branch information
stnbu committed Sep 1, 2018
1 parent 24cd4b4 commit deb45757d4dff3d2ed97175578f2e58110a42a96
Showing with 25 additions and 12 deletions.
  1. +15 −0 coincharts/config.py
  2. +5 −12 coincharts/daemon/base.py
  3. +5 −0 coincharts/schema.py
@@ -0,0 +1,15 @@
# -*- mode: python; coding: utf-8 -*-

import os
import yaml

_config_dir = os.path.expanduser('~/.coincharts')
_api_key_file = os.path.join(_config_dir, 'API_KEY')
_config_file = os.path.join(_config_dir, 'config.yaml')

def get_config():
with open(_config_file) as f:
config = yaml.load(f)
with open(_api_key_file) as f:
config['api_key'] = f.read().strip()
return config
@@ -14,12 +14,14 @@
import logging.handlers
import time

import yaml
from sqlalchemy import Integer, String, Float
import daemon
import daemon.pidfile

from coincharts import schema
from coincharts import schema, config

# We're replacing the module with a dict. Importing the file shouldn't result in reading from disk, etc. That's why.
config = config.get_config()

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@@ -29,11 +31,6 @@
logger.addHandler(ch)


CONFIG_DIR = os.path.expanduser('~/.coincharts')
API_KEY_FILE = os.path.join(CONFIG_DIR, 'API_KEY')
CONFIG_FILE = os.path.join(CONFIG_DIR, 'config.yaml')


class PriceSeries(object):

query_template = dict(
@@ -43,8 +40,7 @@ class PriceSeries(object):
limit=100000,
)
date_format_template = '%Y-%m-%dT%H:%M:%S.%f0Z' # magic
headers = {'X-CoinAPI-Key':
open(API_KEY_FILE).read().strip()}
headers = {'X-CoinAPI-Key': config['api_key']}

# this is the beginning of time if we don't have any local data
first_date = '2018-01-09T00:00:00.0000000Z'
@@ -181,9 +177,6 @@ def worker(dir_path, daemonize=True):
sh.setLevel(logging.DEBUG)
logger.addHandler(sh)

with open(CONFIG_FILE) as f:
config = yaml.load(f)

series = []
for symbol_id in config['history_symbols']:
series.append(PriceSeries(symbol_id, dir_path))
@@ -12,6 +12,11 @@
import sqlalchemy.types
import sqlalchemy.ext.declarative

from coincharts import config

# We're replacing the module with a dict. Importing the file shouldn't result in reading from disk, etc. That's why.
config = config.get_config()

datetime_field = 'time_period_end'
price_field = 'price_close'

0 comments on commit deb4575

Please sign in to comment.