Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [cooper:~/random_repo]$ cat experimental/cooper/fv_6_9_th/fv_six_point_nine.py
- #!/usr/bin/env python3
- import asyncio
- import logging
- import sys
- from datetime import datetime, timedelta
- from typing import Union
- import click
- LOG = logging.getLogger(__name__)
- def _handle_debug(
- ctx: click.core.Context,
- param: Union[click.core.Option, click.core.Parameter],
- debug: Union[bool, int, str],
- ) -> Union[bool, int, str]:
- """Turn on debugging if asked otherwise INFO default"""
- log_level = logging.DEBUG if debug else logging.INFO
- logging.basicConfig(
- format="[%(asctime)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)",
- level=log_level,
- )
- return debug
- async def async_main(debug: bool, start_date: str) -> int:
- year = int(start_date[0:4])
- month = int(start_date[4:6])
- day = int(start_date[6:8])
- if debug:
- print(f"Start Date - Year: {year} Month: {month} Day: {day}")
- start_datetime = datetime(year, month, day)
- ninty_pct_days = int(0.9 * 365.0)
- # Not caring about leaps seconds etc. - We plus 1 as there should be 1 leap lear
- six_point_nine_years = timedelta(days=(6 * 365 + ninty_pct_days + 1))
- print(
- f"With a start date of {start_date} the 6.9 FV is around:\n"
- + f"{start_datetime + six_point_nine_years}"
- )
- return 0
- @click.command(context_settings={"help_option_names": ["-h", "--help"]})
- @click.option(
- "--debug",
- is_flag=True,
- callback=_handle_debug,
- show_default=True,
- help="Turn on debug logging",
- )
- @click.argument("start_date")
- @click.pass_context
- def main(ctx: click.core.Context, **kwargs) -> None:
- """ START_DATE needs to be YYYYMMdd """
- LOG.debug(f"Starting {sys.argv[0]}")
- ctx.exit(asyncio.run(async_main(**kwargs)))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement