예제 #1
0
    def first_time_plaid_transactions(
            self, username
    ):  # add all plaid transactions that already occured into db
        obj = SQLConnection()
        id = obj.find_id_of_user(username)
        data = self.use_token(username)
        data = json.loads(data)
        for items in data['transactions']:
            add = False
            try:
                for things in items["category"]:
                    if things == "Fast Food" or things == "Restaurants":
                        add = True
            except:
                pass

            if add == True:
                obj.add_plaid_transactions_in_db(
                    id, items["_id"]
                )  #adds the transaction id of any restraunts/fast_food
예제 #2
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")