Beispiel #1
0
class UserSurvey:

    users_numbers = [user.get('number') for user in model.getUser()]
    if not users_numbers:
        users_numbers = ["No numbers yet"]
    form = web.form.Form(
        web.form.Textbox("question",
                         web.form.notnull,
                         size=60,
                         description="Question for user:"******"keyword",
                         web.form.notnull,
                         size=10,
                         description="Required SMS response keyword:"),
        web.form.Dropdown("number",
                          args=users_numbers,
                          value=users_numbers[0],
                          description="User mobile number:"),
        web.form.Button("Submit", type="submit", desctiprion="Ask user"),
    )

    def GET(self):
        form = self.form()
        return render.survey(form)

    def POST(self):
        form = self.form()
        # not defined yet ...
        # form.validates()
        data = web.input(_method='post')
        data.question += " Please, respond with %s:yes or %s:no thank you." % (
            data.keyword.lower(), data.keyword.lower())
        model.postSurvey(data.number, data.question, data.keyword.lower())
        sms.send(data.number, data.question)
        raise web.seeother("/")
Beispiel #2
0
def check_balance():
    (balance, gains) = model.get_user_balance(session['username'])
    balance = "${0:.2f}".format(balance)
    gains = "${0:.2f}".format(gains)
    title = ''
    if session['isAdmin'] == False:
        title = 'Account'
        header = "Hi, {}. Here's your portfolio".format(session["username"])
        result = '''
        Your Gains/Loss(Theoretical): {gains}, Your Cash Balance: {balance}
        '''.format(gains=gains, balance=balance)
    else:
        title = 'LeaderBoard'
        model.updateHoldings()
        userlist = model.getUser()
        leaderboard = model.calculateLeaderBoard(userlist)
        header = 'Top 10 LeaderBoard'
        result = ''
        for x in range(len(leaderboard)):
            result += "Rank {}: Name: {} Gains: {}                |".format(
                x + 1, leaderboard[x][0], leaderboard[x][1])
    return render_template('account.html',
                           header=header,
                           title=title,
                           result=result,
                           name=session['username'])
Beispiel #3
0
def index():
    if request.method == "GET":
        pass

    if request.method == "POST":
        email = request.form['email']
        password = request.form['password']
        dbHandler.insertUser(email, password)

    users = dbHandler.getUser()
    return render_template('index.html', users=users)
Beispiel #4
0
def leaderboard():
	if request.method =='GET':
		return render_template('log_in.html')
	else:
		submitted_username = request.form['username']
		submitted_password = request.form['password']
		if submitted_username == 'admin' and submitted_password == 'bruhhh':
			userlist = model.getUser()
			return_list = model.calculateLeaderBoard(userlist) #list of tuples
			return_list.sort(reverse = True, key = operator.itemgetter(1))
			return render_template('leaderboard.html',return_list=return_list)
		else:
			return redirect('/terminal')
Beispiel #5
0
    def POST(self):
        """ Example of incoming message send by Twilio:
       Data from post:<Storage {'Body': u'PCKEYBOARD:YES', 'MessageSid': u'SMcb0e9652e927ef24f391a4824af2b766', 'FromZip': u'', 'From': u'+42190.....', 'SmsMessageSid': u'SMcb0e9652e927ef24f391a4824af2b766', 'AccountSid': u'ACb8209b47e69d92d50..........', 'FromCity': u'', 'ApiVersion': u'2010-04-01', 'To': u'+15742......', 'FromCountry': u'SK', 'NumMedia': u'0', 'ToZip': u'46951', 'ToCountry': u'US', 'NumSegments': u'1', 'SmsStatus': u'received', 'SmsSid': u'SMcb0e9652e927ef24f391a4824af2b766', 'ToCity': u'MACY', 'FromState': u'', 'ToState': u'IN'}>
18.206.172.64:41120 - - [22/Jan/2020 13:47:45]  
        """
        updated_item = None
        data = web.input(_method='post')
        body = str(data.Body).lower()
        # test valid response body and update survey
        if body.find(":yes") != -1 or body.find(":no") != -1:
            keyword, answer = body.split(":")
            updated_item = model.updateSurvey(str(data.From), keyword, answer)
            # send notification based on preferences
            user = model.getUser(str(data.From))
            if updated_item and user:
                notification.send_thanks(user, updated_item.get('question'),
                                         updated_item.get('answer'))
        return "OK"
def routeMe():
	#no token given => abort
	if 'Bearer_token' not in request.headers:
		abort(403)

	#get token from headers 
	token = request.headers['Bearer_token']
	userID = getUserID(token) #get userID from token #TODO
	#if token has no corresponding userID (= not valid)
	if userID == None:
		abort(403)
	
	#get user
	user = getUser(userID)
	#(can be removed after the token ~> userID is completed), but is needed now since getUser(token) return the token as mock
	if user == None: 
		abort(403)

	#return json
	return json.dumps({'user' : user.toJson()}, sort_keys=True, indent= 2 * ' '), 200
Beispiel #7
0
def createleaderboard():
    userlist = model.getUser()
    return_list = model.calculateLeaderBoard(userlist)  #list of tuples
    return_list.sort(reverse=True, key=operator.itemgetter(1))
    return_list = return_list[:10]  #top 10
    return return_list
Beispiel #8
0
 def GET(self):
     users_details = model.getUser()
     users_surveys = model.getSurvey()
     return render.index(users_details, users_surveys)
	def test_remove(self):
		removeUser(self.startUser) #remove user
		user = getUser(self.userID) #try to retrieve the user
		self.assertEqual(None, user) #shouldn't work
	def test_retrieve(self):
		user = getUser(self.userID) #retrieve user
		self.assertEqual(user,self.startUser) #
Beispiel #11
0
def users():
    users = dbHandler.getUser()
    return render_template('users.html', users=users)