Created
April 14, 2017 01:01
-
-
Save gom/3f7255eca612ebd2f6fb02aa63b37e01 to your computer and use it in GitHub Desktop.
Python3.x: Print every Sunday
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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