Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Python3.x: Print every Sunday
from datetime import datetime
from dateutil.relativedelta import relativedelta, SU
from dateutil.rrule import rrule, WEEKLY
import argparse
def main(args):
start = datetime.strptime(args.start_date, "%Y%m%d")
today = datetime.today()
rule = rrule(WEEKLY, byweekday=SU, dtstart=start, until=today)
print(*[ sunday.strftime("%Y%m%d") for sunday in list(rule)])
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('start_date',help='Start Date as "YYYYmmdd"')
args = parser.parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment