Beispiel #1
0
def setup():
    db = firebase.getDB()
    interests = firebase.get_interests(db)
    causes = [{
        "name": x,
        "value": base64.b64encode(x.encode("utf8")).decode("utf8"),
        "active": (x in interests),
    } for x in charity_causes.CAUSES]
    return url_tools.render_template("setup.html", causes=causes)
Beispiel #2
0
def _setup():
    causes = flask.request.form.getlist("cause[]")

    def decode(x):
        return base64.b64decode(str(x).encode("utf8")).decode("utf8")

    causes = [decode(x) for x in causes]

    db = firebase.getDB()

    firebase.change_interests(db, causes)

    return flask.redirect(flask.url_for("app.accountoverview"))
def userCharities():

	charityChoice = flask.request.args.get("choose")
	if charityChoice != None:
		user.setCharity(str(charityChoice))
		return flask.redirect(flask.url_for("app.userCharities"))

	API_key = "5843532b7d4678ebf648c08c09c61d81"
	customers = accounts.get_customers(API_key)
	customers_id = accounts.get_customers_id(customers, app.config.get("CUSTOMER"))
	client = accounts.make_client(API_key, customers_id)

	charityMarkers = []
	charities = []

	if not TESTING:
		try:
			pool = Pool(processes=4)
			charitiesByLocation = find_charity.get_suggestions_by_city(client.city)
			charityMarkers = pool.map(charityMarker, charitiesByLocation[:5],2)
			charityMarkers = [x for x in charityMarkers if x != None]
			charities = recommend.write_final_rec('user1')
		except Exception as e:
			print("SKIPPED")
			print(e)
			pass
	try:
		map = Map(
	    	identifier="view-side",
	    	lat=38.64181689999999,
	    	lng=-83.7657646,
			style="height:500px;width:100%;",
			zoom=12,
			# fit_markers_to_bounds=True,
			markers=charityMarkers,
		)
	except:
		map = None

	db = firebase.getDB()
	topCharity = topDB.getTopCharity(db)

	return url_tools.render_template(
		"usercharities.html",
		map=map,
		charities=charities,
		topCharity = topCharity,
	)
Beispiel #4
0
def _vote():
    form = flask.request.form

    type_ = form.get("submitType")

    if type_ == "vote":
        votedFor = form.get("selectedCharity")
        db_client = firebase.getDB()

        if votedFor != None:
            user.setCharity(votedFor)
            voting_db.increment_charity(db_client, votedFor)
    elif type_ == "tweet":
        tweet()

    return flask.redirect(flask.url_for("mod_voting.vote"))
Beispiel #5
0
def vote():

    db_client = firebase.getDB()

    try:
        charities = voting_db.get_charities(db_client)
    except Exception as e:
        return "Error retrieving charities: " + str(e)

    for charity in charities:
        charity["description"] = redis.hget("charity:" + charity["name"],
                                            "mission")

    _charities = json.dumps(charities)
    return url_tools.render_template(
        "voting.html",
        charities=charities,
        _charities=_charities,
    )