Skip to content

Instantly share code, notes, and snippets.

@tombasche
Last active March 1, 2017 22:15
Show Gist options
  • Save tombasche/de18461d306ad2c12ad12da6aec1749f to your computer and use it in GitHub Desktop.
Save tombasche/de18461d306ad2c12ad12da6aec1749f to your computer and use it in GitHub Desktop.
Population Clock - using the ABS population API
import requests, json, time, os
ABS_URL = 'http://www.abs.gov.au/api/demography/populationprojection'
def getData():
r = requests.get(ABS_URL)
return json.loads(r.text)
def getPopulation():
text = getData()
return int(text['popNow'])
def getRateOfChange():
text = getData()
return int(float(text['rateSecond']))
def cls():
os.system('cls' if os.name=='nt' else 'clear')
timeDelta = getRateOfChange()
while True:
popThen = getPopulation()
print 'The population is',popThen
time.sleep(timeDelta)
popNow = getPopulation()
delta = popNow - popThen
if delta >= 1:
print '+',delta
elif delta < 0:
print '-',delta
else:
cls()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment