Skip to content

Commit

Permalink
Command line program setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujit Maharjan authored and Sujit Maharjan committed Jul 12, 2020
1 parent ecc29c1 commit 2ad6815
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,42 @@

A python library that assists you in converting date from BS to AD and vice versa.

# Installation

```bash
pip install datebs
```

## usage

### Commandline

convert the date 2020-07-01 into BS
```bash
python -m datebs BS --date 2020-07-01
```

using from python
```python
from .datebs import DateBS
import argparse
import datetime

if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="python -m datebs",description='Convert date from BS to AD and vice-versa')
parser.add_argument('calendar',type=str, help="calendar system in which date is to be displayed [AD|BS]")
parser.add_argument('--date',type=str, help="date opporsite to the calendar system")
args = parser.parse_args()
if (args.calendar == "BS"):
if args.date:
dateBS = DateBS.from_AD(datetime.datetime.strptime(args.date, "%Y-%m-%d"))
else:
dateBS = DateBS.from_AD(datetime.datetime.now())
print(dateBS)
else:
if args.date:
dateBS = DateBS.from_string(args.date)
print(dateBS.to_AD())
else:
print(datetime.datetime.now())
```
1 change: 0 additions & 1 deletion datebs/__init__.py

This file was deleted.

22 changes: 22 additions & 0 deletions datebs/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from .datebs import DateBS
import argparse
import datetime

if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="python -m datebs",description='Convert date from BS to AD and vice-versa')
parser.add_argument('calendar',type=str, help="calendar system in which date is to be displayed [AD|BS]")
parser.add_argument('--date',type=str, help="date opporsite to the calendar system")
args = parser.parse_args()
if (args.calendar == "BS"):
if args.date:
dateBS = DateBS.from_AD(datetime.datetime.strptime(args.date, "%Y-%m-%d"))
else:
dateBS = DateBS.from_AD(datetime.datetime.now())
print(dateBS)
else:
if args.date:
dateBS = DateBS.from_string(args.date)
print(dateBS.to_AD())
else:
print(datetime.datetime.now())

18 changes: 0 additions & 18 deletions datebs/datebs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,3 @@ def days_in_month(year:int, month:int):
return DateBS.months_in_year(year)[month-1]


if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Convert date from BS to AD and vice-versa')
parser.add_argument('calendar',type=str, help="calendar system in which date is to be displayed [AD|BS]")
parser.add_argument('--date',type=str, help="date opporsite to the calendar system")
args = parser.parse_args()
if (args.calendar == "BS"):
if args.date:
dateBS = DateBS.from_AD(datetime.datetime.strptime(args.date, "%Y-%m-%d"))
else:
dateBS = DateBS.from_AD(datetime.datetime.now())
print(dateBS)
else:
if args.date:
dateBS = DateBS.from_string(args.date)
print(dateBS.to_AD())
else:
print(datetime.datetime.now())

0 comments on commit 2ad6815

Please sign in to comment.