Skip to content

Commit 3018cca

Browse files
committed
refactor: move from __init__.py to core.py
1 parent e7ad8c7 commit 3018cca

4 files changed

Lines changed: 56 additions & 38 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.cache/
2+
__pycache__/
3+
*.pyc
4+
5+
dist/
6+
build/
7+
*.egg-info/

randomtimestamp/__init__.py

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,15 @@
1-
from random import randint
2-
from datetime import timedelta as td, datetime as dt,date,time
1+
"""
2+
Python module to generate random time stamps.
3+
"""
34

45
__title__ = 'randomtimestamp'
5-
__version__ = '0.1.0'
6+
__version__ = '2.0.0'
67
__author__ = "Shraddha Kishan Tripathi"
78
__license__ = 'GPL v3.0'
89

9-
START_DT = date(1950, 1, 1)
10-
END_DT = dt.now().date()
11-
MY_FORMAT = "%d-%m-%Y %H:%M:%S"
1210

13-
def validate(start_year,text): # Function to validate and correct the user-supplied arguments
14-
try:
15-
start_year = int(start_year)
16-
start_year = (1950,start_year) [start_year>=1950]
17-
except:
18-
start_year = 1950
19-
global START_DT
20-
START_DT = date(start_year, 1, 1)
21-
if text not in [True,False]:
22-
text = True
23-
return start_year,text
24-
25-
def accesstime(date1, date2): # Function which generates random datetime object
26-
n = randint(0, int((date2 - date1).days)+1)
27-
date1 = date1 + td(n)
28-
hour = randint(0,23)
29-
minute = randint(0,59)
30-
second = randint(0,59)
31-
tm = time(hour,minute,second)
32-
return dt.combine(date1,tm)
11+
from .core import randomtimestamp
3312

34-
def gettime():
35-
return accesstime(START_DT,END_DT)
36-
37-
38-
def randomtimestamp(start_year = 1950,text = True): # Main function that is invoked by the user
39-
start_year,text = validate(start_year,text)
40-
tst = gettime()
41-
if text == True:
42-
return tst.strftime(MY_FORMAT)
43-
else:
44-
return tst
13+
__all__ = [
14+
'randomtimestamp'
15+
]

randomtimestamp/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from randomtimestamp import randomtimestamp
1+
from .core import randomtimestamp
22

33

44
def main():

randomtimestamp/core.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from random import randint
2+
from datetime import timedelta as td, datetime as dt,date,time
3+
4+
5+
START_DT = date(1950, 1, 1)
6+
END_DT = dt.now().date()
7+
MY_FORMAT = "%d-%m-%Y %H:%M:%S"
8+
9+
def validate(start_year,text): # Function to validate and correct the user-supplied arguments
10+
try:
11+
start_year = int(start_year)
12+
start_year = (1950,start_year) [start_year>=1950]
13+
except:
14+
start_year = 1950
15+
global START_DT
16+
START_DT = date(start_year, 1, 1)
17+
if text not in [True,False]:
18+
text = True
19+
return start_year,text
20+
21+
def accesstime(date1, date2): # Function which generates random datetime object
22+
n = randint(0, int((date2 - date1).days)+1)
23+
date1 = date1 + td(n)
24+
hour = randint(0,23)
25+
minute = randint(0,59)
26+
second = randint(0,59)
27+
tm = time(hour,minute,second)
28+
return dt.combine(date1,tm)
29+
30+
def gettime():
31+
return accesstime(START_DT,END_DT)
32+
33+
34+
def randomtimestamp(start_year = 1950,text = True): # Main function that is invoked by the user
35+
start_year,text = validate(start_year,text)
36+
tst = gettime()
37+
if text == True:
38+
return tst.strftime(MY_FORMAT)
39+
else:
40+
return tst

0 commit comments

Comments
 (0)