Last active
March 1, 2017 22:15
-
-
Save tombasche/de18461d306ad2c12ad12da6aec1749f to your computer and use it in GitHub Desktop.
Population Clock - using the ABS population API
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
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