Python Forum
Student project - alert action when X happens Y amt of times, how?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Student project - alert action when X happens Y amt of times, how?
#1
Disclaimer - I am not a professional dev/engineer
Use case = check if X happens Y amt of times, do something/alert
For the sake of this post, let's saying X = user tweet a certain #X can really be anything, so let's not focus on TWTR API/limits/security. For example, X can be when CNN posts certain keyword article or user posts a new tiktok, it doesn't matter in this post.
My guess for requirements is...HW - need some box running 24/7, like an AWS ec2 boxDB - I assume you need a DB to store checks (the Y amt of times)
My pseudo code is
def checker():
	# check if user tweets
def addtodb():
	# store the check so we can count, basically a ++
def checkdb():
	# query db to check when count is 3
def endaction():
	# alert me
if (checker() == true):
	addtodb()
if (checkdb == 3):
	endaction()
Am I going about this correctly? Some initial questions that come to mind is how to I endlessly run a check? I don't think it makes sense to run this code (.py file) every 1 second in an infinite loop via cron. Maybe can leverage streaming/kafka? Any particular examples, libraries, of packages you would recommend?
Reply
#2
Yes, if your "checker" is hitting an external API you don't want to do that constantly. Often you don't need to be up-to-the-second, so polling at an interval (say 20 minutes) is sufficient but doesn't overload external servers.

Think about if this should happen in an interval. Do you want to know if this happens 3 times ever? Or maybe 3 times in a calendar day, or 3 times in a 24 hour period? So you'll have to have a counter and some method to reset the counter.

The checker depends on the specific API. Nice would be to keep track of the last time you checked. Then ask the API for any events since that time. That cuts down the data that gets transmitted. Otherwise you might have to parse a lot of data and see if any of it is in the relevant time frame.
Reply
#3
APIs have rate limits. You can just sleep at whatever rate relative to it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Student grader and sorter for assignment RazeAD 7 3,180 Feb-11-2021, 06:29 AM
Last Post: RazeAD
  Generating a student's transcript [OOP concept] aongkeko 2 2,697 Dec-01-2020, 06:43 AM
Last Post: buran
  Create code for input names and score for 15 student Davin 2 2,078 Sep-21-2020, 08:49 AM
Last Post: DeaD_EyE
  New Python Student = Does this code look right? musicjoeyoung 6 3,434 May-07-2020, 02:39 PM
Last Post: musicjoeyoung
  Student grade program help debug ccm1776 3 5,168 Nov-14-2018, 02:41 AM
Last Post: stullis
  Find how many times a user played an artist and how many times disruptfwd8 1 2,615 May-04-2018, 08:32 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020