I built a whatsapp chatbot that takes in keywords and returns some output dependent on the keyword sent. The data is then sent to a database. I would like to count the number of times the userid of the person sending the keyword appears in my database today. Userid in this context is the person's number.
I started off by just simply trying to count how many times a number appears, but cannot get this first part right
Here is a sample of my code
class Users(db.Model):
__tablename__ = 'users'
cell_number = db.Column(db.Integer, primary_key = True)
interaction_date = db.Column(db.DateTime, default = datetime.now(pytz.timezone('Africa/Harare')))
request_key = db.Column(db.String(64000))
counter = db.Column(db.Integer)
...
total = user_object.query.filter_by(user_object.cell_number).filter_by(user_object.interaction_date == func.current_date()).count()
This returns the error message:
TypeError: filter_by() takes 1 positional argument but 2 were given
UPDATE
After reading the comment sent I made a few changes to my code which changed the issue slightly, so now I am returning a count for userids, however I cannot seem to filter for interactions that occurred today.
Here is my modified code:
interaction_date = Users.interaction_date
current = datetime.now(pytz.timezone('Africa/Harare')).strftime('%d-%m-%y')
total = Users.query.filter(user_object.cell_number == cleaned_number).filter(interaction_date == current).count()
This however returns a count of 0 despite there being atleast 17 interactions with the number i am using. Here is a sample of my database
cell_number interaction_date request_key
123 2020-03-25 13:51:44 xv
123 2020-03-25 13:51:50 cv
121 2020-03-24 22:22:30 dfdf
Its important to add that interaction_date returns the value None, I am not sure why I am not retrieving the interaction_date value from my database