The code you have provided has the effect of sending a single message to every one of your subscribers. To have any "frequency" to speak of, you need to run this program occasionally -- for example, you can set up a cron
job (or a Windows equivalent) that executes it once every X time -- say, once per minute.
Won't that mean your subscribers will get spammed with messages once per minute? It would, unless we add something else: a way to record when the message has been sent, or, equivalently, when the next message is due.
Specifically, along with each address, you need to store: the content of the message you'd like to send to them this time; the interval with which you intend to send the messages; and the last time that we sent a message to that address.
For this, normal applications use a database. You are using Pandas Dataframes, which probably have sufficient capabilities, but they're definitely harder to use for this. Since you have said in the comments that this is a homework question, and also because I have no experience with Pandas, I will instead provide some ORM-like pseudocode.
from dataclasses import dataclass
import database
import time
import mailer
@dataclass
class DatabaseRow:
""" Single row in database of email addresses and associated data """
email: str # email address to send message to
subject: str # message subject
body: str # message body
send_interval: int # or float -- number of seconds between each message
next_send_at: Optional[int] # int or None (or float or None); Unix time at which to send next message; if None, send immediately
for row in database.get_all_rows():
current_time = time.time() # this returns Unix time: the number of seconds since 1 Jan 1970
if row.next_send_at is None or current_time < row.next_send_at:
# it is not time to send it to them yet; don't do anything
continue
mailer.send(row.address, row.subject, row.body)
row.next_send_at = current_time + row.send_interval # the next time we'll send a message is (send_interval) away from now
row.save()