Beispiel #1
0
def show_latest_catalog():
    databaseManager = DatabaseManager()
    categories = databaseManager.get_categories()
    items = databaseManager.get_latest_items()
    return render_template("latest_item_catalog.html",
                           categories=categories,
                           items=items,
                           category_id=0)
Beispiel #2
0
def show_catalog(id):
    databaseManager = DatabaseManager()
    categories = databaseManager.get_categories()
    items = databaseManager.get_items(id)
    itemcount = databaseManager.get_items_count(id)
    return render_template("catalog.html",
                           categories=categories,
                           items=items,
                           category_id=id,
                           itemcount=itemcount)
Beispiel #3
0
class PicManager:
    def __init__(self):
        self.data_manager = DatabaseManager()
        self.pic_site = "https://source.unsplash.com/category/"
        self.pic_size = "/1400x1200"
        self.pic_to_upload = "pic1.jpg"

    # zwraca liste 20 defaultowych tagow LIKE COMENT FOLLOW SHOUTOUT
    def get_default_category_tags(self, list):
        list.extend(self.data_manager.get_count_tag_by_category('Likes', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Comments', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Follow me', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Shoutout', 5))
        return list

    # zwraca liste tagow z zadanej kategorii
    # 20 tagow defaultowych i okreslone parametrem limit tagi z zadanej kategorii
    def get_tags(self, category, limit):
        list = []
        list.extend(self.data_manager.get_count_tag_by_category(category, limit))
        self.get_default_category_tags(list)
        return list

    def urban_url(self):
        return "buildings"

    # dodaje zdjecie
    def upload(self, list):
        list = self.get_tags("Urban", 10)
        context = ssl._create_unverified_context()
        #category_url = get_category_url(category)
        urllib.urlretrieve(self.pic_site + "buildings" + self.pic_size, self.pic_to_upload, context=context)
        self.cut_image()
        with pynstagram.client('urbanshot__', 'kluza1') as client:
            tags = ''
            for tag in list:
                tags = tags + '#' + tag + ' '
            client.upload('pic1.jpg', tags)
        return list

    # przycina zdjecie do kwadratu
    def cut_image(self):
        img = Image.open(self.pic_to_upload)
        half_width = img.size[0] / 2
        half_height = img.size[1] / 2
        img1 = img.crop(
            (
                half_width - 450,
                half_height - 450,
                half_width + 450,
                half_height + 450
            )
        )
        img1.save(self.pic_to_upload)
Beispiel #4
0
class PicManager:
    def __init__(self):
        self.data_manager = DatabaseManager()
        self.pic_site = "https://source.unsplash.com/category/"
        self.pic_size = "/1400x1200"
        self.pic_to_upload = "pic1.jpg"

    # zwraca liste 20 defaultowych tagow LIKE COMENT FOLLOW SHOUTOUT
    def get_default_category_tags(self, list):
        list.extend(self.data_manager.get_count_tag_by_category('Likes', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Comments', 5))
        list.extend(self.data_manager.get_count_tag_by_category(
            'Follow me', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Shoutout', 5))
        return list

    # zwraca liste tagow z zadanej kategorii
    # 20 tagow defaultowych i okreslone parametrem limit tagi z zadanej kategorii
    def get_tags(self, category, limit):
        list = []
        list.extend(
            self.data_manager.get_count_tag_by_category(category, limit))
        self.get_default_category_tags(list)
        return list

    def urban_url(self):
        return "buildings"

    # dodaje zdjecie
    def upload(self, list):
        list = self.get_tags("Urban", 10)
        context = ssl._create_unverified_context()
        #category_url = get_category_url(category)
        urllib.urlretrieve(self.pic_site + "buildings" + self.pic_size,
                           self.pic_to_upload,
                           context=context)
        self.cut_image()
        with pynstagram.client('urbanshot__', 'kluza1') as client:
            tags = ''
            for tag in list:
                tags = tags + '#' + tag + ' '
            client.upload('pic1.jpg', tags)
        return list

    # przycina zdjecie do kwadratu
    def cut_image(self):
        img = Image.open(self.pic_to_upload)
        half_width = img.size[0] / 2
        half_height = img.size[1] / 2
        img1 = img.crop((half_width - 450, half_height - 450, half_width + 450,
                         half_height + 450))
        img1.save(self.pic_to_upload)
Beispiel #5
0
def create_new_item(category_id):
    databaseManager = DatabaseManager()
    if request.method == "POST":
        databaseManager.create_items(request.form["category"],
                                     request.form["name"],
                                     request.form["description"],
                                     user_id=login_session['user_id'])
        if category_id == 0:
            return redirect(url_for("show_latest_catalog"))
        else:
            return redirect(url_for("show_catalog", id=category_id))
    else:
        categories = databaseManager.get_categories()
        return render_template("create_item.html",
                               category_id=category_id,
                               categories=categories)
 def __init__(self, login, password):
     self.data_manager = DatabaseManager()
     self.pic_site = {
         "Swimming"  : "https://source.unsplash.com/category/people/?swimming",
         "Running"   : "https://source.unsplash.com/category/people/?running",
         "Cars"      : "https://source.unsplash.com/category/objects/?cars",
         "Sports"    : "https://source.unsplash.com/category/people/?sports",
         "Winter"    : "https://source.unsplash.com/category/nature/?winter",
         "Summer"    : "https://source.unsplash.com/category/nature/?summer",
         "Friends"   : "https://source.unsplash.com/category/people/?friends",
         "Boys"      : "https://source.unsplash.com/category/people/?boys",
         "Baby"      : "https://source.unsplash.com/category/people/?baby",
         "People"    : "https://source.unsplash.com/category/people",
         "Sea"       : "https://source.unsplash.com/category/nature/?sea",
         "Flower"    : "https://source.unsplash.com/category/nature/?flower",
         "Urban"     : "https://source.unsplash.com/category/buildings",
         "Love"      : "https://source.unsplash.com/category/people/?love",
         "Nature"    : "https://source.unsplash.com/category/nature",
         "Food"      : "https://source.unsplash.com/category/food"
     }
     self.pic_size = "/1400x1200"
     self.pic_to_upload = "pic1.jpg"
     self.login = login
     self.password = password
     self.category = "brak"
Beispiel #7
0
 def __update_plan_type(self, plan_type: PlanType):
     self.__plan_type = plan_type
     with DatabaseManager.connect() as database_connection:
         database_connection.execute(
             "UPDATE magic_castles SET plan_type = ? WHERE hostname = ?",
             (self.__plan_type.value, self.__hostname),
         )
         database_connection.commit()
Beispiel #8
0
    def run(self):
        database = DatabaseManager(self._args)
        try:
            character_manager = CharacterManager(database)
            discord_manager = Bot(character_manager,
                                  command_prefix='MG!',
                                  prefix='MG!',
                                  command_attrs=dict(hidden=True))

            self.load_cogs(discord_manager)

            discord_manager.run(self._token)

        except KeyboardInterrupt:
            database.close()
            logging.warning("Exiting...")
            sys.exit(1)
Beispiel #9
0
def edit_item(item_id, category_id):
    databaseManager = DatabaseManager()
    if request.method == "GET":
        item = databaseManager.get_item(item_id)
        categories = databaseManager.get_categories()
        return render_template("edit_item.html",
                               item=item,
                               categories=categories,
                               category_id=category_id)
    else:
        item = databaseManager.update_item(item_id, request.form["name"],
                                           request.form["description"],
                                           request.form["category"])
        flash("update item successfully")
        if category_id == 0:
            return redirect(url_for("show_latest_catalog"))
        else:
            return redirect(url_for("show_catalog", id=item.category_id))
Beispiel #10
0
 def join_chow(cls, chow_id, token):
     db = database.getInstance()
     client = boto3.client('cognito-idp', region_name='us-east-2')
     user = client.get_user(AccessToken=token)
     chow = db.get_item_as_json('Chow', chow_id)
     chow['joinedUser'] = user['Username']
     chow['joinedName'] = user['UserAttributes'][2]['Value'] #username is stored here
     chow['joinedEmail'] = user['UserAttributes'][3]['Value'] #email is stored here
     success = db.put_item('Chow', chow)
     return jsonify({"success":success})
Beispiel #11
0
 def unjoin_chow(cls, chow_id, token):
     db = database.getInstance()
     client = boto3.client('cognito-idp', region_name='us-east-2')
     user = client.get_user(AccessToken=token)
     chow = db.get_item_as_json('Chow', chow_id)
     chow['joinedUser'] = None
     chow['joinedName'] = None
     chow['joinedEmail'] = None
     success = db.put_item('Chow', chow)
     return jsonify({"success":success})
Beispiel #12
0
    def get_joined_chows(cls, token):
        db = database.getInstance()
        client = boto3.client('cognito-idp', region_name='us-east-2')
        user = client.get_user(AccessToken=token)
        chows = db.scan_as_json_with_criteria('Chow', 'joinedUser', user['Username'])

        chows = chowutil.remove_soft_delete(chows)
        chows = chowutil.remove_expired(chows)
        
        return jsonify(chows)
Beispiel #13
0
def myDynamodb(request):
    # Create table for testing
    db = database.getInstance()
    db.create_table('ChowTest')

    def remove_table():
        print('delete table ChowTest')
        db.delete_table('ChowTest')

    request.addfinalizer(remove_table)
    return db
Beispiel #14
0
 def get_plan_type(self) -> PlanType:
     if self.__plan_type is None:
         with DatabaseManager.connect() as database_connection:
             result = database_connection.execute(
                 "SELECT plan_type FROM magic_castles WHERE hostname = ?",
                 (self.get_hostname(), ),
             ).fetchone()
         if result:
             self.__plan_type = PlanType(result[0])
         else:
             self.__plan_type = PlanType.NONE
     return self.__plan_type
Beispiel #15
0
 def get_owner(self):
     if self.__owner is None:
         with DatabaseManager.connect() as database_connection:
             result = database_connection.execute(
                 "SELECT owner FROM magic_castles WHERE hostname = ?",
                 (self.get_hostname(), ),
             ).fetchone()
         if result:
             self.__owner = result[0]
         else:
             self.__owner = None
     return self.__owner
Beispiel #16
0
 def get_status(self) -> ClusterStatusCode:
     if self.__status is None:
         with DatabaseManager.connect() as database_connection:
             result = database_connection.execute(
                 "SELECT status FROM magic_castles WHERE hostname = ?",
                 (self.get_hostname(), ),
             ).fetchone()
         if result:
             self.__status = ClusterStatusCode(result[0])
         else:
             self.__status = ClusterStatusCode.NOT_FOUND
     return self.__status
Beispiel #17
0
    def get_chows(cls, remove_expired=True):
        db = database.getInstance()
        chows = db.scan_as_json('Chow')

        # remove chows that are marked as 'isDeleted'
        chows = chowutil.remove_soft_delete(chows)
        
        if (remove_expired):
            chows = chowutil.remove_expired(chows)
        
        #remove chows that have been "chowed in" on
        chows = chowutil.remove_joined_users(chows)

        response = jsonify(chows)
        return response
Beispiel #18
0
def delete_item(item_id, category_id):
    if request.method == "GET":
        databaseManager = DatabaseManager()
        item = databaseManager.get_item(item_id)
        return render_template("delete_item.html",
                               item=item,
                               category_id=category_id)
    else:
        flash("delete item successfully")
        databaseManager = DatabaseManager()
        databaseManager.delete_item(item_id)
        if category_id == 0:
            return redirect(url_for("show_latest_catalog"))
        else:
            return redirect(url_for("show_catalog", id=category_id))
Beispiel #19
0
    def __update_status(self, status: ClusterStatusCode):
        self.__status = status
        with DatabaseManager.connect() as database_connection:
            database_connection.execute(
                "UPDATE magic_castles SET status = ? WHERE hostname = ?",
                (self.__status.value, self.__hostname),
            )
            database_connection.commit()

        # Log cluster status updates for log analytics
        print(
            json.dumps({
                "hostname": self.get_hostname(),
                "status": self.__status.value,
                "owner": self.get_owner(),
            }),
            flush=True,
        )
Beispiel #20
0
 def __init__(self, configuration):
     self.configuration = configuration
     self.last_msg = 0
     self.bot = None
     self.ttt_games = {}
     self.database_manager = DatabaseManager()
     if self.database_manager.db.engine is not None:
         self.event_manager = EventManager(self.database_manager)
         self.time_manager = TimeManager(self.event_manager)
     else:
         self.database_manager = None
         self.event_manager = None
         self.time_manager = None
     self.id_manager = IdentityManager(self.database_manager)
     self.nickname_manager = NicknameManager(self.database_manager)
     self.birthday_manager = BirthdayManager(self.database_manager)
     self.wheel_manager = WheelManager(self.database_manager)
     self.reminder_manager = ReminderManager()
Beispiel #21
0
 def decorator(*args, **kwargs):
     auth_type = AuthType(config.get("auth_type") or "NONE")
     with DatabaseManager.connect() as database_connection:
         if auth_type == AuthType.SAML:
             try:
                 # Note: Request headers are interpreted as ISO Latin 1 encoded strings.
                 # Therefore, special characters and accents in givenName and surname are not correctly decoded.
                 user = AuthenticatedUser(
                     database_connection,
                     edu_person_principal_name=request.
                     headers["eduPersonPrincipalName"],
                     given_name=request.headers["givenName"],
                     surname=request.headers["surname"],
                     mail=request.headers["mail"],
                 )
             except KeyError:
                 # Missing an authentication header
                 raise UnauthenticatedException
         else:
             user = AnonymousUser(database_connection)
         return route_handler(user, *args, **kwargs)
class PicManager:
    def __init__(self, login, password):
        self.data_manager = DatabaseManager()
        self.pic_site = {
            "Swimming"  : "https://source.unsplash.com/category/people/?swimming",
            "Running"   : "https://source.unsplash.com/category/people/?running",
            "Cars"      : "https://source.unsplash.com/category/objects/?cars",
            "Sports"    : "https://source.unsplash.com/category/people/?sports",
            "Winter"    : "https://source.unsplash.com/category/nature/?winter",
            "Summer"    : "https://source.unsplash.com/category/nature/?summer",
            "Friends"   : "https://source.unsplash.com/category/people/?friends",
            "Boys"      : "https://source.unsplash.com/category/people/?boys",
            "Baby"      : "https://source.unsplash.com/category/people/?baby",
            "People"    : "https://source.unsplash.com/category/people",
            "Sea"       : "https://source.unsplash.com/category/nature/?sea",
            "Flower"    : "https://source.unsplash.com/category/nature/?flower",
            "Urban"     : "https://source.unsplash.com/category/buildings",
            "Love"      : "https://source.unsplash.com/category/people/?love",
            "Nature"    : "https://source.unsplash.com/category/nature",
            "Food"      : "https://source.unsplash.com/category/food"
        }
        self.pic_size = "/1400x1200"
        self.pic_to_upload = "pic1.jpg"
        self.login = login
        self.password = password
        self.category = "brak"

    # zwraca liste 20 defaultowych tagow LIKE COMENT FOLLOW SHOUTOUT
    def get_default_category_tags(self, list):
        list.extend(self.data_manager.get_count_tag_by_category('Likes', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Comments', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Follow me', 5))
        list.extend(self.data_manager.get_count_tag_by_category('Shoutout', 5))
        return list

    # zwraca liste tagow z zadanej kategorii
    # 20 tagow defaultowych i okreslone parametrem limit tagi z zadanej kategorii
    def get_tags(self, category, limit):
        list = []
        list.extend(self.data_manager.get_count_tag_by_category(category, limit))
        self.get_default_category_tags(list)
        return list

    # dodaje zdjecie
    def upload(self):
        list = self.get_tags(self.category, 10)
        context = ssl._create_unverified_context()
        category_url = self.pic_site[self.category] + self.pic_size
        urllib.urlretrieve(category_url, self.pic_to_upload, context=context)
        self.cut_image()
        with pynstagram.client(self.login, self.password) as client:
            tags = ''
            for tag in list:
                tags = tags + '#' + tag + ' '
            client.upload('pic1.jpg', tags)
        print("Photo uploaded")
        return list

    # przycina zdjecie do kwadratu
    def cut_image(self):
        img = Image.open(self.pic_to_upload)
        half_width = img.size[0] / 2
        half_height = img.size[1] / 2
        img1 = img.crop(
            (
                half_width - 450,
                half_height - 450,
                half_width + 450,
                half_height + 450
            )
        )
        img1.save(self.pic_to_upload)
Beispiel #23
0
        def terraform_apply(destroy: bool):
            try:
                self.__rotate_terraform_logs(apply=True)
                with open(
                        self.__get_cluster_path(TERRAFORM_APPLY_LOG_FILENAME),
                        "w") as output_file:
                    environment_variables = environ.copy()
                    dns_manager = DnsManager(self.get_domain())
                    environment_variables.update(
                        dns_manager.get_environment_variables())
                    environment_variables["OS_CLOUD"] = DEFAULT_CLOUD
                    if destroy:
                        environment_variables["TF_WARN_OUTPUT_ERRORS"] = "1"
                    run(
                        [
                            "terraform",
                            "apply",
                            "-input=false",
                            "-no-color",
                            "-auto-approve",
                            self.__get_cluster_path(
                                TERRAFORM_PLAN_BINARY_FILENAME),
                        ],
                        cwd=self.__get_cluster_path(),
                        stdout=output_file,
                        stderr=output_file,
                        check=True,
                        env=environment_variables,
                    )
                if destroy:
                    # Removes the content of the cluster's folder, even if not empty
                    rmtree(self.__get_cluster_path(), ignore_errors=True)
                    with DatabaseManager.connect() as database_connection:
                        database_connection.execute(
                            "DELETE FROM magic_castles WHERE hostname = ?",
                            (self.get_hostname(), ),
                        )
                        database_connection.commit()
                else:
                    self.__update_status(
                        ClusterStatusCode.PROVISIONING_RUNNING)

                if not destroy:
                    provisioning_manager = ProvisioningManager(
                        self.get_hostname())

                    # Avoid multiple threads polling the same cluster
                    if not provisioning_manager.is_busy():
                        try:
                            provisioning_manager.poll_until_success()
                            status_code = ClusterStatusCode.PROVISIONING_SUCCESS
                        except PuppetTimeoutException:
                            status_code = ClusterStatusCode.PROVISIONING_ERROR

                        self.__update_status(status_code)

            except CalledProcessError:
                logging.info(
                    "An error occurred while running terraform apply.")

                self.__update_status(ClusterStatusCode.DESTROY_ERROR if destroy
                                     else ClusterStatusCode.BUILD_ERROR)
            finally:
                self.__remove_existing_plan()
Beispiel #24
0
    def __plan(self, *, destroy, existing_cluster):
        plan_type = PlanType.DESTROY if destroy else PlanType.BUILD
        if existing_cluster:
            self.__remove_existing_plan()
            previous_status = self.get_status()
        else:
            with DatabaseManager.connect() as database_connection:
                database_connection.execute(
                    "INSERT INTO magic_castles (hostname, cluster_name, domain, status, plan_type, owner) VALUES (?, ?, ?, ?, ?, ?)",
                    (
                        self.get_hostname(),
                        self.get_cluster_name(),
                        self.get_domain(),
                        ClusterStatusCode.CREATED.value,
                        plan_type.value,
                        self.get_owner(),
                    ),
                )
                database_connection.commit()
            mkdir(self.__get_cluster_path())
            previous_status = ClusterStatusCode.CREATED

        self.__update_status(ClusterStatusCode.PLAN_RUNNING)
        self.__update_plan_type(plan_type)

        if not destroy:
            self.__configuration.update_main_tf_json_file()

        try:
            run(
                ["terraform", "init", "-no-color", "-input=false"],
                cwd=self.__get_cluster_path(),
                capture_output=True,
                check=True,
            )
        except CalledProcessError:
            self.__update_status(previous_status)
            raise PlanException(
                "An error occurred while initializing Terraform.",
                additional_details=f"hostname: {self.get_hostname()}",
            )

        self.__rotate_terraform_logs(apply=False)
        with open(self.__get_cluster_path(TERRAFORM_PLAN_LOG_FILENAME),
                  "w") as output_file:
            environment_variables = environ.copy()
            dns_manager = DnsManager(self.get_domain())
            environment_variables.update(
                dns_manager.get_environment_variables())
            environment_variables["OS_CLOUD"] = DEFAULT_CLOUD
            try:
                run(
                    [
                        "terraform",
                        "plan",
                        "-input=false",
                        "-no-color",
                        "-destroy=" + ("true" if destroy else "false"),
                        "-out=" + self.__get_cluster_path(
                            TERRAFORM_PLAN_BINARY_FILENAME),
                    ],
                    cwd=self.__get_cluster_path(),
                    env=environment_variables,
                    stdout=output_file,
                    stderr=output_file,
                    check=True,
                )
            except CalledProcessError:
                if destroy:
                    # Terraform returns an error if we try to destroy a cluster when the image
                    # it was created with does not exist anymore (e.g. CentOS-7-x64-2019-07). In these cases,
                    # not refreshing the terraform state (refresh=false) solves the issue.
                    try:
                        run(
                            [
                                "terraform",
                                "plan",
                                "-refresh=false",
                                "-input=false",
                                "-no-color",
                                "-destroy=" + ("true" if destroy else "false"),
                                "-out=" + self.__get_cluster_path(
                                    TERRAFORM_PLAN_BINARY_FILENAME),
                            ],
                            cwd=self.__get_cluster_path(),
                            env=environment_variables,
                            stdout=output_file,
                            stderr=output_file,
                            check=True,
                        )
                    except CalledProcessError:
                        # terraform plan fails even without refreshing the state
                        self.__update_status(previous_status)
                        raise PlanException(
                            "An error occurred while planning changes.",
                            additional_details=
                            f"hostname: {self.get_hostname()}",
                        )
                else:
                    self.__update_status(previous_status)
                    raise PlanException(
                        "An error occurred while planning changes.",
                        additional_details=f"hostname: {self.get_hostname()}",
                    )

        with open(self.__get_cluster_path(TERRAFORM_PLAN_JSON_FILENAME),
                  "w") as output_file:
            try:
                run(
                    [
                        "terraform",
                        "show",
                        "-no-color",
                        "-json",
                        TERRAFORM_PLAN_BINARY_FILENAME,
                    ],
                    cwd=self.__get_cluster_path(),
                    stdout=output_file,
                    check=True,
                )
            except CalledProcessError:
                self.__update_status(previous_status)
                raise PlanException(
                    "An error occurred while exporting planned changes.",
                    additional_details=f"hostname: {self.get_hostname()}",
                )

        self.__update_status(previous_status)
Beispiel #25
0
 def create_chow(cls, chow):
     db = database.getInstance()
     success = db.put_item('Chow', chow)
     response = jsonify({"success": success})
     return response
Beispiel #26
0
def get_items_by_category(id):
    databaseManager = DatabaseManager()
    items = databaseManager.get_items(id)
    return jsonify(items=[i.serialize for i in items])
Beispiel #27
0
def get_items_by_id(item_id):
    databaseManager = DatabaseManager()
    item = databaseManager.get_item(item_id)
    return jsonify(item.serialize)
Beispiel #28
0
def show_item(item_id, category_id):
    databaseManager = DatabaseManager()
    item = databaseManager.get_item(item_id)
    return render_template("show_item.html",
                           item=item,
                           category_id=category_id)
Beispiel #29
0
 def delete_chow(cls, chow_id):
     db = database.getInstance()
     success = db.soft_delete_item('Chow', chow_id)
     return jsonify({"success":success})
Beispiel #30
0
from flask import Flask, send_file, send_from_directory
from resources.magic_castle_api import MagicCastleAPI
from resources.progress_api import ProgressAPI
from resources.available_resources_api import AvailableResourcesApi
from resources.user_api import UserAPI
from flask_cors import CORS
from models.cloud.openstack_manager import OpenStackManager
from database.schema_manager import SchemaManager
from database.database_manager import DatabaseManager
from models.configuration import config

# Exit with an error if the clouds.yaml is not found or the OpenStack API can't be reached
OpenStackManager.test_connection()

# Update the database schema to the latest version
with DatabaseManager.connect() as database_connection:
    SchemaManager(database_connection).update_schema()

app = Flask(__name__)

# Allows all origins on all routes (not safe for production)
CORS(
    app,
    origins=config["cors_allowed_origins"],
)

magic_castle_view = MagicCastleAPI.as_view("magic_castle")
app.add_url_rule(
    "/api/magic-castles",
    view_func=magic_castle_view,
    defaults={"hostname": None},
Beispiel #31
0
#! /usr/bin/env python3

from database.database_manager import DatabaseManager

database = DatabaseManager()

# Get top 3 articles
top_three_articles = database.get_popular_three_articles()

print("1. What are the most popular three articles of all time?")

for article in top_three_articles:
    print("\"" + article[0] + "\" -- " + str(article[1]) + " views")

# Get top authors of all time

print("2. Who are the most popular article authors of all time?")

top_authors = database.get_popular_authors()

for authors in top_authors:
    print(authors[0] + " -- " + str(authors[1]) + " views")

# Get error requests which are more than 1%

print("3. On which days did more than 1% of requests lead to errors?")

fail_request = database.get_error_requests()

for bad_request in fail_request:
    print(bad_request[0] + " -- " + str(bad_request[1]) + "% errors")
Beispiel #32
0
 def get_chow(cls, chow_id):
     db = database.getInstance()
     chow = db.get_item_as_json('Chow', chow_id)
     response = jsonify(chow)
     return response
Beispiel #33
0
 def __init__(self):
     self.data_manager = DatabaseManager()
     self.pic_site = "https://source.unsplash.com/category/"
     self.pic_size = "/1400x1200"
     self.pic_to_upload = "pic1.jpg"
Beispiel #34
0
 def update_chow(cls, chow_id, chow):
     db = database.getInstance()
     chow['id'] = chow_id
     success = db.put_item('Chow', chow)
     return jsonify({"success": success, "chow": chow})