def create_app(): app = Flask(__name__) app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', True) app.config.from_object(Config) Config.init_app(app) db.init_app(app) # add other flask extensions app.register_blueprint(demo, url_prefix='') # add blueprint here return app
def load_tweet(tweet_type): config = Config() with open( os.path.join(config.PROJECT_ROOT, 'tests', 'data', f'{tweet_type}.json')) as f: tweet = json.load(f) return tweet
def get_user_tz(): config = Config() try: tz = pytz.timezone(config.TIMEZONE) except pytz.exceptions.UnknownTimeZoneError: tz = pytz.utc return tz
def get_auth(): config = Config() if config.CONSUMER_KEY is None or config.CONSUMER_SECRET is None or config.OAUTH_TOKEN is None or config.OAUTH_TOKEN_SECRET is None: raise Exception( 'Twitter API keys need to be set for streaming to work.') auth = OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET) auth.set_access_token(config.OAUTH_TOKEN, config.OAUTH_TOKEN_SECRET) return auth
def rollbar_init(): config = Config() if config.ENV == 'prd': rollbar.init( config.ROLLBAR_ACCESS_TOKEN, # access token 'production', # Environment name root=os.path.dirname(os.path.realpath( __file__)), # server root directory, makes tracebacks prettier allow_logging_basic_config=False)
def __init__(self, bucket=None): self.config = Config() if bucket is None: self.bucket = self.config.S3_BUCKET elif bucket == 'public': self.bucket = self.config.S3_BUCKET_PUBLIC elif bucket == 'sagemaker': self.bucket = self.config.S3_BUCKET_SAGEMAKER else: raise ValueError(f'Unknown bucket {bucket}')
def __init__(self, tweet, project, image_storage_mode='active'): self.tweet = tweet self.es_index_name = tweet['_tracking_info']['es_index_name'] self.project_slug = project self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.tmp_path = os.path.join(self.config.APP_DIR, 'tmp') self.image_storage_mode = image_storage_mode self.redis_s3_queue = RedisS3Queue() self.s3 = S3Handler() self.logger = logging.getLogger(__name__) self.download_media_types = ['photo', 'animated_gif']
def __init__(self, source=None, destination=None, file_name=''): self.source = f"/{source}/" self.file_name = '' self.destination = f"/{destination}/" self.file = "test.tiff" self.config = Config() self.watcher = OnWatchFile() self.watcher.connect_directory_monitoring() basedir = os.path.abspath(os.path.dirname(__file__)) self.basedir_files_tiff = os.path.join(basedir, "files_test/file.tiff") self.basedir_files_xml = os.path.join(basedir, "files_test/file.xml")
def __init__(self, project, project_locales=None, key_namespace_counts='trending-topics-counts', max_queue_length=1e4, project_keywords=None, **args): super().__init__(self, **args) self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.project = project self.max_queue_length = int(max_queue_length) self.project_locales = project_locales self.trending_topics_index_name = f'trending_topics_{project}' self.es = Elastic() self.redis = Redis() if not isinstance(project_keywords, list): self.project_keywords = [] else: self.project_keywords = project_keywords # Counts queue: holds mixture of retweet + tweet token counts self.pq_counts_weighted = PriorityQueue( project, namespace=self.namespace, key_namespace=key_namespace_counts, max_queue_length=self.max_queue_length) # Retweet counts queue: holds counts only from retweets self.pq_counts_retweets = PriorityQueue( project, namespace=self.namespace, key_namespace=key_namespace_counts + '-retweets', max_queue_length=self.max_queue_length) # Tweet counts queue: holds counts only by tweets self.pq_counts_tweets = PriorityQueue( project, namespace=self.namespace, key_namespace=key_namespace_counts + '-tweets', max_queue_length=self.max_queue_length) # set blacklisted tokens (to be ignored by tokenizer) self.default_blacklisted_tokens = [ 'RT', 'breaking', 'amp', 'covid19', 'covid-19', 'coronaviru' ] self.blacklisted_tokens = self._generate_blacklist_tokens( project_keywords=project_keywords)
def __init__(self, project, es_index_name=None, project_locales=None, key_namespace='trending-tweets', max_queue_length=1e4, expiry_time_ms=2 * 24 * 3600 * 1000, **args): super().__init__(self, **args) self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.project = project self.key_namespace = key_namespace self.max_queue_length = int(max_queue_length) self.pq = PriorityQueue(project, namespace=self.namespace, key_namespace=self.key_namespace, max_queue_length=self.max_queue_length) self.expiry_time_ms = expiry_time_ms self.es_index_name = es_index_name self.es = Elastic() self.project_locales = project_locales
from flask import Flask from app.ext import init_ext from app.models import db from app.settings import Config def create_app(): app = Flask(__name__) app.config.from_object(Config()) db.init_app(app) init_ext(app) return app print(Config().SQLALCHEMY_DATABASE_URI)
def __init__(self): self.config = Config() self.client = mandrill.Mandrill(self.config.MANDRILL_API_KEY) self.logger = logging.getLogger(__name__)
def create_app(): app = Flask(__name__) app.config.from_object(Config()) db.init_app(app) init_ext(app) return app
def __init__(self, **args): super().__init__(**args) self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.dump_folder = os.path.join(self.config.PROJECT_ROOT, 'logs')
def __init__(self, **args): super().__init__(**args) self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.counts_namespace = 'counts' self.media_name_spaces = ['photo', 'video', 'animated_gif']
from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from app.settings import get_logger, Config logger = get_logger('Connection database') config = Config() """ Database connection that is then used throughout the project """ try: engine = create_engine( config.url_engine, echo=False, max_identifier_length=30, ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() except Exception as err: logger.error(f"Error connecting: cx_Oracle.init_oracle_client() {err}")
def __init__(self, project): super().__init__() self.config = Config() self.namespace = self.config.REDIS_NAMESPACE self.queue_namespace = 'predict_queue' self.project = project
def __init__(self): self.config = Config() self.bucket = self.config.S3_BUCKET_SAGEMAKER self.logger = logging.getLogger(__name__)
def setUp(self): self.file = "test.tiff" self.setup_module() self.config = Config() self.config.schema = '' self.on_watch_file = OnWatchFile() self.on_watch_file.session = self.session basedir = os.path.abspath(os.path.dirname(__file__)) self.basedir_monitoring = os.path.join(basedir, "monitoring") self.basedir_files_tiff = os.path.join(basedir, "files_test/file.tiff") self.basedir_files_xml = os.path.join(basedir, "files_test/file.xml") list_file = [ { "alloc_size": 0, "create_time": 1606743144.2058148, "file_attributes": 16, "file_id": None, "file_size": 0, "filename": ".", "isDirectory": True, "isNormal": False, "isReadOnly": False, "last_access_time": 1608919592.1831565, "last_attr_change_time": 1608919592.1831565, "last_write_time": 1608919592.1831565, "short_name": "", }, { "alloc_size": 0, "create_time": 1606743144.2058148, "file_attributes": 16, "file_id": None, "file_size": 0, "filename": "", "isDirectory": True, "isNormal": False, "isReadOnly": False, "last_access_time": 1608919592.1831565, "last_attr_change_time": 1608919592.1831565, "last_write_time": 1608919592.1831565, "short_name": "", }, { "alloc_size": 1798144, "create_time": float(time.time()), "file_attributes": 32, "file_id": None, "file_size": 1797347, "filename": "file.tiff", "isDirectory": False, "isNormal": False, "isReadOnly": False, "last_access_time": float(time.time()), "last_attr_change_time": float(time.time()), "last_write_time": float(time.time()), "short_name": "", }, ] self.list_file = [] for key, element in enumerate(list_file): self.list_file.append( namedtuple("SharedFile", element.keys())(*element.values()) ) self.id_type_import = self.type_import_id(self.session, "new_file")