<commit_before># Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(ace-n): replace this with an API call
from sample_data import SAMPLE_CAMPAIGNS, SAMPLE_DONATIONS

from flask import Blueprint, redirect, request, render_template


campaigns_bp = Blueprint("campaigns", __name__, template_folder="templates")


@campaigns_bp.route("/")
def list_campaigns():
    return render_template("home.html", campaigns=SAMPLE_CAMPAIGNS)


@campaigns_bp.route("/createCampaign", methods=["GET"])
def new_campaign():
    return render_template("create-campaign.html")


@campaigns_bp.route("/createCampaign", methods=["POST"])
def save_campaign():
    # TODO: do something with the collected data
    print("Name: ", request.form["name"])
    print("Goal: ", request.form["goal"])
    print("Managers: ", request.form["managers"])

    return redirect("/")


@campaigns_bp.route("/viewCampaign")
def webapp_view_campaign():
    campaign_id = request.args["campaign_id"]
    campaign_instance = [
        campaign for campaign in SAMPLE_CAMPAIGNS if campaign["id"] == campaign_id
    ][0]
    return render_template("view-campaign.html", campaign=campaign_instance)<commit_msg>demo(website): showcase API integration (#82)<commit_after># Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from sample_data import SAMPLE_DONATIONS

from flask import Blueprint, redirect, request, render_template

import requests

campaigns_bp = Blueprint("campaigns", __name__, template_folder="templates")

API_URL = 'https://api-pwrmtjf4hq-uc.a.run.app'

@campaigns_bp.route("/")
def list_campaigns():
    campaigns = requests.get(API_URL + '/campaigns').json()
    return render_template("home.html", campaigns=campaigns)


@campaigns_bp.route("/createCampaign", methods=["GET"])
def new_campaign():
    return render_template("create-campaign.html")


@campaigns_bp.route("/createCampaign", methods=["POST"])
def save_campaign():
    # TODO: do something with the collected data
    print("Name: ", request.form["name"])
    print("Goal: ", request.form["goal"])
    print("Managers: ", request.form["managers"])

    return redirect("/")


@campaigns_bp.route("/viewCampaign")
def webapp_view_campaign():
    campaigns = requests.get(API_URL + '/campaigns').json()
    campaign_instance = campaigns[0]
    return render_template("view-campaign.html", campaign=campaign_instance)
{'fraction_non_alphanumeric': 0.11666176902732883, 'fraction_numerical': 0.006171025565677344, 'mean_word_length': 5.155515370705244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3682142', 'n_tokens_mistral': 1014, 'n_tokens_neox': 944, 'n_words': 305}