def create_app(): app = Flask(__name__, template_folder='yelp_beans/templates') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = get_config().get('DATABASE_URL_PROD', "sqlite://") db.init_app(app) from yelp_beans.routes.api.v1.meeting_requests import meeting_requests from yelp_beans.routes.api.v1.metrics import metrics_blueprint from yelp_beans.routes.api.v1.preferences import preferences_blueprint from yelp_beans.routes.api.v1.user import user_blueprint from yelp_beans.routes.tasks import tasks # Cron Endpoint app.register_blueprint(tasks, url_prefix='/tasks') # Api Endpoints app.register_blueprint(meeting_requests, url_prefix='/v1/meeting_request') app.register_blueprint(metrics_blueprint, url_prefix='/v1/metrics') app.register_blueprint(preferences_blueprint, url_prefix='/v1/user/preferences') app.register_blueprint(user_blueprint, url_prefix='/v1/user') with app.app_context(): db.create_all() return app
def __init__(self, *args, **kwargs): self.data_providers = [] data_providers = get_config()['data_providers'] for provider in data_providers: cls = locate(provider['class']) kwargs_keys = set(provider.keys()) - set(['class']) kwargs = {key: provider[key] for key in kwargs_keys} self.data_providers.append(cls(**kwargs))
def get_previous_meetings(subscription, cooldown=None): if cooldown is None: cooldown = get_config()['meeting_cooldown_weeks'] meetings = defaultdict(list) # get all meeting specs from x weeks ago til now time_threshold_for_meetings = datetime.now() - timedelta(weeks=cooldown) meeting_specs = [ spec for spec in MeetingSpec.query.filter( MeetingSpec.datetime > time_threshold_for_meetings, MeetingSpec.meeting_subscription_id == subscription.id ).all() ] logging.info('Previous Meeting History: ') logging.info([meeting.datetime.strftime("%Y-%m-%d %H:%M") for meeting in meeting_specs]) if meeting_specs == []: return set([]) # get all meetings from meeting specs meeting_keys = [meeting.id for meeting in Meeting.query.filter( Meeting.meeting_spec_id.in_( [meet.id for meet in meeting_specs])).all()] if meeting_keys == []: return set([]) # get all participants from meetings participants = MeetingParticipant.query.filter( MeetingParticipant.meeting_id.in_(meeting_keys) ).all() if participants == []: return set([]) # group by meeting Id for participant in participants: meetings[participant.meeting.id].append(participant.user) # ids are sorted, all matches should be in increasing order by id for the matching algorithm to work disallowed_meetings = set([tuple(sorted(meeting, key=lambda Key: Key.id)) for meeting in meetings.values()]) logging.info('Past Meetings') logging.info([tuple([meeting.get_username() for meeting in meeting]) for meeting in disallowed_meetings]) disallowed_meetings = {tuple([meeting.id for meeting in meeting]) for meeting in disallowed_meetings} return disallowed_meetings