Skip to content

Instantly share code, notes, and snippets.

@blbradley
Created January 5, 2016 04:05
Show Gist options
  • Save blbradley/42bcc8176f8503a64778 to your computer and use it in GitHub Desktop.
Save blbradley/42bcc8176f8503a64778 to your computer and use it in GitHub Desktop.
Date parameterization - Python vs Bash
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)
#!/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
@blbradley
Copy link
Author

Python wins!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment