Creating Wishlist2Text website – Part 1

Hello, I am going to describe how I create https://wishlist2text.appspot.com website. I use flask for it.

Start by creating virtualenv. Make sure virtualenv package is installed. 

virtualenv venv
source venv/Scripts/activate

# Install flask
pip install flask

Create main.py which will be used to start the app. The filename should be main.py because this is the filename which google app engine expects. App engine I am using for hosting.
At the top of the file, I am importing create_app function. And run the app.  The function will be created later.

from wishlist2text import create_app

app = create_app()

if __name__ == "__main__":
    app.run()

As the next step, I need to create a wishlist2text package, Create a folder with the same name, and inside of this folder create __init__.py file. This file lets python know that wishlist2text folder is a package.
In the init file I will create create_app function and init flask Class. Als I am going to use flask blueprints. Blueprint allows making my app modular. Create rest of required folder, static for js, CSS and images, templates for HTML and scan_wishlist. Scan wishlist will store my first flask blueprint. Let’s back to __init__.py. At the top, I need to import Flask and Blueprint class, and flask config, which will be created later.

from flask import Flask, Blueprint
from wishlist2text.scan_wishlist.api import SteamWishlist

Now I am ready to create create_app function. In the function instance of Flask class need to be created and specified which config is used. Next blueprint needs to be imported and registered (Will be created later). In the end, flask instance needs to be returned.

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(Config)

    from wishlist2text.scan_wishlist.routes import wishlist

    app.register_blueprint(wishlist)

    return app

I am importing Config class but it not created. Let’s fix it. Create in the root of the wishlist2text folder, where is __init__.py located config.py. In this file, I will store all my app config. Example of config.

import os


class Config(object):
    SECRET_KEY = os.environ.get("SECRET_KEY") or "secret_key"
    RESOLVE_VANITY = (
        "http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001"
    )
    GET_PLAYER_SUMMARIES_API = (
        "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v1"
    )
    API_KEY = os.environ.get("API_KEY")
    WISHLIST_URL = "https://store.steampowered.com/wishlist/profiles"

API links will stay the same, but to make an app work SECRET_KEY and API_KEY environment variables need to be created. SECRET_KEY – Set the secret key to some random bytes. Keep this really secret! and API_KEY is steam API token. Can be generated here. In the next post, I will explain how to create flask blueprint. Stay tuned.