Created
November 9, 2012 16:19
-
-
Save melissaboiko/4046614 to your computer and use it in GitHub Desktop.
Tell whether Mercury is retrograde (astrologically bad for computer networks)
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
#!/usr/bin/env python2.6 | |
# -*- coding: utf-8 -*- | |
from datetime import * | |
import argparse | |
import sys | |
# this script has no actual code to calculate retrograde motion. sorry! | |
CSI = '[' | |
RED = CSI + '31' + 'm' | |
BLACK = CSI + '30' + 'm' | |
YELLOW = CSI + '33' + 'm' | |
BLUE = CSI + '34' + 'm' | |
DEFCOLOR = CSI + '39' + 'm' | |
BOLD = CSI + '1' + 'm' | |
NOBOLD = CSI + '22' + 'm' | |
def bold(s): | |
return BOLD + s + NOBOLD | |
def red(s): | |
return RED + s + DEFCOLOR | |
def blue(s): | |
return BLUE + s + DEFCOLOR | |
def yellow(s): | |
return YELLOW + s + DEFCOLOR | |
def gray(s): | |
return bold(BLACK + s + DEFCOLOR) | |
dateranges=( | |
((2012,7,14), (2012,8,7)), | |
((2012,11,6), (2012,11,26)), | |
((2013,2,23), (2013,3,17)), | |
((2013,6,26), (2013,7,20)), | |
((2013,10,21), (2013,11,10)), | |
((2014,2,6), (2014,2,28)), | |
((2014,6,7), (2014,7,1)), | |
((2014,10,4), (2014,10,25)), | |
((2015,1,21), (2015,2,11)), | |
((2015,5,18), (2015,6,11)), | |
((2015,9,17), (2015,10,9)), | |
((2016,1,5), (2016,1,25)), | |
((2016,4,28), (2016,5,22)), | |
((2016,8,30), (2016,9,21)), | |
((2016,12,19), (2017,1,8)), | |
((2017,4,9), (2017,5,3)), | |
((2017,8,12), (2017,9,5)), | |
((2017,12,2), (2017,12,22)), | |
((2018,3,22), (2018,4,15)), | |
((2018,7,25), (2018,8,18)), | |
((2018,11,16), (2018,12,6)), | |
((2019,3,5), (2019,3,28)), | |
((2019,7,7), (2019,7,31)), | |
((2019,10,31), (2019,11,20)), | |
((2020,2,16), (2020,3,9)), | |
((2020,6,17), (2020,7,12)), | |
((2020,10,13), (2020,11,3)), | |
((2021,1,30), (2021,2,20)), | |
((2021,5,29), (2021,6,22)), | |
((2021,9,26), (2021,10,18)), | |
((2022,1,14), (2022,2,3)), | |
((2022,5,10), (2022,6,3)), | |
((2022,9,9), (2022,10,2)), | |
((2022,12,29), (2023,1,18)), | |
) | |
dates=[] | |
for r in dateranges: | |
dates.append( ( date(r[0][0], r[0][1], r[0][2]) , | |
date(r[1][0], r[1][1], r[1][2]) )) | |
today=date.today() | |
retro=False | |
for (start, end) in dates: | |
if (today >= start) and (today <= end): | |
retro=True | |
break | |
parser = argparse.ArgumentParser(description='Show whether Mercury motion is retrograde.') | |
parser.add_argument('-c', '--chart', dest='chart', action='store_true', | |
help='also show a chart of retrograde dates') | |
args = parser.parse_args() | |
if retro: | |
print bold(red('℞☿ Be careful!')) + ' Retrograde mercury today.' | |
else: | |
print bold(blue('☿')) + ' Mercury is prograde today.' | |
if args.chart: | |
print 'Calendar of retrograde dates:' | |
nextdue_done=False | |
for (start, end) in dates: | |
s = start.strftime('%Y-%m-%d') | |
e = end.strftime('%Y-%m-%d') | |
fmt = '%s\tto\t%s' % (s, e) | |
if (today > end): | |
print gray(fmt) | |
elif (today >= start) and (today <= end): | |
print bold(red(fmt + '←')) | |
elif not nextdue_done: | |
print bold(yellow(fmt + '*')) | |
nextdue_done=True | |
else: | |
print fmt | |
if retro: | |
sys.exit(1) | |
else: | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment