Created
January 5, 2016 04:05
-
-
Save blbradley/42bcc8176f8503a64778 to your computer and use it in GitHub Desktop.
Date parameterization - Python vs Bash
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
from datetime import date, datetime | |
from dateutil.relativedelta import relativedelta | |
from six import print_ | |
exchanges = { | |
'bitfinex': 'btcusd', | |
'bitstamp': 'btcusd', | |
'okcoin': 'btccny', | |
} | |
for exchange, asset in exchanges.items(): | |
dt = date(2015, 1, 1) | |
today = datetime.utcnow().date() | |
while (dt <= today): | |
print_(exchange, asset, dt.year, dt.month) | |
dt += relativedelta(months=1) |
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 bash | |
get_year_and_month() { | |
echo $(date --date=$1 +"%Y %m") | |
} | |
add_month() { | |
echo $(date --date="$1 + 1 month" +%Y-%m-%d) | |
} | |
startdate=2015-01-01 | |
enddate=2016-01-01 | |
for exchange in "bitfinex btcusd" "bitstamp btcusd" "okcoin btccny"; do | |
date="$startdate" | |
while [ $date != $(add_month $enddate) ]; do | |
echo "$exchange" $(get_year_and_month $date) | |
date=$(add_month $date) | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python wins!