Esempio n. 1
0
    def set_settings(self, db_session: Session, setting_to_set: SettingSet):
        new_setting = Setting(welcome_speech=setting_to_set.welcome_speech,
                              color_button=setting_to_set.color_button,
                              community_id=setting_to_set.community_id)

        db_session.add(new_setting)
        db_session.commit()
        db_session.refresh(new_setting)
        return new_setting
Esempio n. 2
0
    def add_time_table(self, db_session: Session, time_to_set: TimeTableSet):
        new_time_table = TimeTable(manager_id=time_to_set.manager_id,
                                   day_of_the_week=time_to_set.day_of_the_week,
                                   start_work=time_to_set.start_work,
                                   end_work=time_to_set.end_work)

        db_session.add(new_time_table)
        db_session.commit()
        db_session.refresh(new_time_table)
        return new_time_table
Esempio n. 3
0
    def update_settings(self, db_session: Session, community_id: int,
                        setting_to_update: SettingUpdate):
        update_setting = db_session.query(Setting).filter_by(
            community_id=community_id).first()
        if update_setting is None:
            raise NoResultFound('Setting not found')

        update_setting.welcome_speech = setting_to_update.welcome_speech
        update_setting.color_button = setting_to_update.color_button

        db_session.add(update_setting)
        db_session.commit()
        db_session.refresh(update_setting)
        return update_setting
    def add_manager(self, db_session: Session, community_id: int,
                    manager_to_add: ManagerCreate):
        community = (db_session.query(Community).options(
            lazyload("managers")).get(community_id))
        manager = Manager(
            phone=manager_to_add.phone,
            name=manager_to_add.name,
            is_blocked=manager_to_add.is_blocked,
        )

        community.managers.append(manager)
        db_session.add(community)
        db_session.commit()
        db_session.refresh(community)
        return community
Esempio n. 5
0
    def update_time_table(self, db_session: Session, time_table_id: int,
                          time_to_update: TimeTableUpdate):
        update_time = db_session.query(TimeTable).filter_by(
            id=time_table_id).first()
        if update_time is None:
            raise NoResultFound('Time Table not found')

        update_time.day_of_the_week = time_to_update.day_of_the_week
        update_time.start_work = time_to_update.start_work
        update_time.end_work = time_to_update.end_work

        db_session.add(update_time)
        db_session.commit()
        db_session.refresh(update_time)
        return update_time
Esempio n. 6
0
    def download_recipe_meta_data(cls):
        """Downloads recipe metadata"""
        session = Session()

        # loading bar based on recipe count
        recipe_count = 1
        recipe_batch_count = cls.get_recipe_batch_count()
        cls.logger.info('Parsing and saving recipe meta data')
        with tqdm(total=recipe_batch_count, unit=' recipes') as pbar:
            for page in range(1, cls.max_api_page):
                req = requests.get(RECIPE_API, params={'page': page})
                soup = BeautifulSoup(req.text, 'html.parser')
                section = soup.find('section', {'id': 'archive-recipes'})
                recipes = section.findAll('li')
                for recipe_html in recipes:
                    if recipe_count > RECIPE_BATCH_COUNT:
                        return

                    slug = recipe_html.a['href'].replace(
                        '/plant-based-recipes/', '')
                    recipe = get_or_create(session, Recipe, slug=slug)

                    recipe.name = recipe_html.img['title']
                    cls.logger.info('Parsing recipe: ' + recipe.name)
                    recipe.slug = slug
                    recipe.url = 'https://' + cls.hostname + \
                        str(recipe_html.a['href'])
                    recipe.origin = SERVICE_CODE
                    recipe.country = 'US'

                    assets = []
                    thumbnail_url = recipe_html.img['src']
                    thumbnail = get_or_create(
                        session, Asset, url=thumbnail_url)
                    thumbnail.type = 'thumbnail'
                    thumbnail.url = thumbnail_url
                    assets.append(thumbnail)

                    recipe.assets = assets

                    session.add(recipe)
                    session.commit()

                    pbar.update(1)
                    recipe_count += 1
                page += 1
    def create(self, db_session: Session, community_to_create: CommunityCreate,
               user_id: int):
        info = services.vk_service.get_community_info(
            community_to_create.api_key, community_to_create.community_vk_id)
        community = Community(
            community_vk_id=community_to_create.community_vk_id,
            avatar_url=info["photo_200"],
            name=info["name"],
        )

        user = db_session.query(User).get(user_id)
        if user is not None:
            community.admins.append(user)

        db_session.add(community)
        db_session.commit()
        db_session.refresh(community)
        return community
Esempio n. 8
0
	def create_user(self, db_session: Session, user_to_create: UserCreate):
		existing_user = self.get_by_username(db_session, user_to_create.username)
		if existing_user is not None:
			raise Exception('User already exists')
		
		new_user = User(
			username=user_to_create.username,
			first_name=user_to_create.first_name,
			last_name=user_to_create.last_name,
			is_admin=user_to_create.is_admin,
			vk_id=user_to_create.vk_id,
			avatar_url=user_to_create.avatar_url,
			email=user_to_create.email,
			phone=user_to_create.phone,
			password=user_to_create.password,
		)

		new_user.set_password(user_to_create.password)
		db_session.add(new_user)
		db_session.commit()
		db_session.refresh(new_user)
		return new_user