text stringlengths 1 93.6k |
|---|
if(flag):
|
time.sleep(3)
|
# <FILESEP>
|
"""
|
All settings you can change for running slack channel reaper will live in this file.
|
"""
|
import os
|
from datetime import datetime, timedelta
|
def get_channel_reaper_settings():
|
""" This returns a dictionary of all settings. """
|
days_inactive = int(os.environ.get('DAYS_INACTIVE', 60))
|
return {
|
'admin_channel': os.environ.get('ADMIN_CHANNEL', ''),
|
'days_inactive': days_inactive,
|
# set MIN_MEMBERS and any channels larger than this in people
|
# are exempt from archiving. 0 is no limit.
|
'min_members': int(os.environ.get('MIN_MEMBERS', 0)),
|
'dry_run': (os.environ.get('DRY_RUN', 'true') == 'true'),
|
'slack_token': os.environ.get('SLACK_TOKEN', ''),
|
'too_old_datetime': (datetime.now() - timedelta(days=days_inactive)),
|
'whitelist_keywords': os.environ.get('WHITELIST_KEYWORDS', ''),
|
'skip_subtypes': {'channel_leave', 'channel_join'},
|
'skip_channel_str': os.environ.get('SLACK_SKIP_PURPOSE', '%noarchive'),
|
}
|
# <FILESEP>
|
"""
|
Stocks database.
|
"""
|
import collections
|
import itertools
|
import logging
|
import sqlite3
|
import util
|
class Stocks:
|
"""Stocks data generator."""
|
# feature vector definition
|
Features = collections.namedtuple("Features",
|
["askhi", "bidlo", "ret", "vol", "ask", "bid", "retx", "trend"])
|
# default features are all zero
|
default_features = Features._make([0] * len(Features._fields))
|
def __init__(self, path):
|
"""Open database.
|
Parameters:
|
path -- database path
|
"""
|
self._db = sqlite3.connect(path)
|
self._db.row_factory = sqlite3.Row
|
def close(self):
|
"""Close database."""
|
self._db.close()
|
def permno(self, symbol):
|
"""Return the CRSP permno for a symbol."""
|
# query data
|
cursor = self._db.cursor()
|
cursor.execute("""
|
SELECT permno
|
FROM names
|
WHERE tsymbol = :symbol
|
ORDER BY date DESC
|
LIMIT 1
|
""", dict (symbol = symbol))
|
row = cursor.fetchone()
|
cursor.close()
|
return row["permno"] if row else None
|
def permnos(self, symbols):
|
"""Return the CRSP permnos for a sequence of symbols."""
|
return [self.permno(symbol) for symbol in symbols]
|
def timeseries(self, permno, start = None, end = None):
|
"""Return the timeseries of features for an issue.
|
Parameters:
|
permno -- CRSP permno
|
start -- start date (None = start of time)
|
end -- end date (None = end of time)
|
"""
|
# query data
|
cursor = self._db.cursor()
|
cursor.execute("""
|
SELECT prices.date,
|
prices.askhi,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.