예제 #1
0
파일: fitbit.py 프로젝트: RusseII/interpet
    def add_events_fitness(self):

        db = SQLConnection()
        users = db.get_all_users()
        category = "fitness"
        for username in users:
            if db.is_fitbit_setup(username):
                pet_name = db.find_pet_of_user(username)
                xp_change = self.make_score_fitness(username)
                type1 = 1
                wore_fitbit = True

                if xp_change == None:
                    db.insert_events(
                        username, category, "no_effect", 0,
                        "You did not sleep with your fitbit, so your score was uneffected",
                        type1)
                    wore_fitbit = False

                if wore_fitbit:
                    db.change_xp(username, xp_change)
                    if xp_change <= -300:
                        message = "You have seriously harmed " + pet_name + " from neglagence yesterday. Make it up to " + pet_name + " by exercising today"
                        pet_status = "sick"
                    elif xp_change <= 100:
                        message = pet_name + " is sad from the lack of exercise yesterday"
                        pet_status = "sick"
                    elif xp_change <= 300:
                        message = pet_name + " got some exercise yesterday, but is still eager to play today "
                        pet_status = "happy"
                    else:
                        message = pet_name + " got plenty of exercise yesterday and as a result he is very happy! +" + str(
                            xp_change) + " xp"
                        pet_status = "happy"
                    print "added"
                    current_xp = db.get_xp(username)
                    db.insert_events(username, category, pet_status, xp_change,
                                     message, type1, current_xp)
예제 #2
0
파일: fitbit.py 프로젝트: RusseII/interpet
    def make_score_sleep(self):
        type = "sleep"
        db = SQLConnection()
        users = db.get_all_users()
        for username in users:
            if db.is_fitbit_setup(username):

                pet_name = db.find_pet_of_user(username)
                result = self.get_user_data(username, type)

                print result
                result = result['summary']['totalTimeInBed']
                db.change_xp(username, result)
                print result
                db = SQLConnection()
                current_xp = db.get_xp(username)
                if result == 0:
                    db.insert_events(
                        username, "sleep", "home", 0,
                        "You did not sleep with your fitbit, so your score was uneffected",
                        "1", current_xp)
                elif result <= 400:
                    db.insert_events(
                        username, "sleep", "tired", -250,
                        pet_name + " is tired from the lack of sleep. -250 xp",
                        "1", current_xp)
                elif result <= 420:
                    db.insert_events(
                        username, "sleep", "tired", -125,
                        pet_name + " is tired from the lack of sleep. -250 xp",
                        "1", current_xp)
                else:
                    db.insert_events(
                        username, "sleep", "home", 250, pet_name +
                        " feels great today! It must be from getting enough sleep. +250 xp",
                        "1", current_xp)
예제 #3
0
    def check_plaid_event(
            self,
            username):  #checks the database ids and plaid ids for differences
        plaid_list = self.get_list_of_restraunt_transactions(username)
        obj = SQLConnection()
        user_id = obj.find_id_of_user(username)
        database_list = obj.get_users_transactions(username)
        test = list(set(plaid_list) - set(database_list))
        if test != []:  #if there is a difference aka update
            data = self.plaid_results
            data = json.loads(data)
            for items in test:
                for things in data['transactions']:
                    if things['_id'] == items:
                        fast_food = False
                        for classifications in things["category"]:
                            if classifications == "Fast Food":
                                fast_food = True
                        if fast_food == True:
                            obj.add_event_list(user_id, "1")
                            obj.add_plaid_transactions_in_db(
                                user_id, things['_id'])
                            obj.change_xp(username, -500)
                        else:
                            obj.add_event_list(user_id, "2")
                            obj.add_plaid_transactions_in_db(
                                user_id, things['_id'])
                            obj.change_xp(username, -250)
        return "done"


# plaid().check_plaid_event("rwr21")
#plaid().check_plaid_event("rwr21")

# print type(response)
#             print type (response.content)
#             d = json.loads(response.content)
#             #print d
#             print type(d)
#            # print response.content
#             for items in d['transactions']:

#                 #TODO SQL DATABSE TO KEEP TRACK OF LVL FAST FOOD -200 restraunt -100

#                # print items['date']
#                 try:
#                     for things in items['category']:
#                         fast_food=False
#                         if things=="Fast Food": #finds if user bought fast food
#                             fast_food=True
#                            #print items['name']
#                     if fast_food==False:
#                          for things in items['category']:
#                             if things=="Restaurants":
#                                 print things
#                                 print items['name']#finds name of restraunt that is not fast food

#                 except:
#                     pass
#                 #print items
#             #print type (response.content.)
#             # User connected
#             data = response.json()
#
#rint SQLConnection().get_users_transactions("rwr21")
#plaid().first_time_plaid_transactions("rwr21")

#print plaid().use_token("rwr21")
#plaid().create_user("rwr21","chase","rratcliffe57",p)
#plaid().check_plaid_event("rwr21")