-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdilbert.py
More file actions
30 lines (26 loc) · 738 Bytes
/
dilbert.py
File metadata and controls
30 lines (26 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import pytz
from datetime import datetime
from datetime import timedelta
from random import randrange
def getStrip():
randDate = random_date()
comicDate = randDate.strftime("%Y-%m-%d")
url = 'http://dilbert.com/strip/' + comicDate
return url
def random_date():
"""
This function will return a random datetime between two datetime
objects.
"""
start = datetime.strptime('1989-04-16', '%Y-%m-%d')
end = datetime.now()
delta = end - start
int_delta = (delta.days * 24 * 60 * 60) + delta.seconds
random_second = randrange(int_delta)
return start + timedelta(seconds=random_second)
def main():
p = getStrip()
print p
if __name__ == '__main__':
main()