Scraper fuer Geodaten der Pendlerstatistik der Arbeitsagentur
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fetch-pendler.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import sys
  2. import json
  3. import requests
  4. pendlerUrl = 'https://statistik.arbeitsagentur.de/PendlerData'
  5. pendlerParams = { 'year_month' : '201706', 'view' : 'renderPendler' }
  6. f = open('kreise.json', 'r')
  7. kreise = f.read()
  8. f.close()
  9. geojson = json.loads(kreise)
  10. while not all('auspendler' in f['properties'] for f in geojson['features']):
  11. for i in range(len(geojson['features'])):
  12. f = geojson['features'][i];
  13. if 'auspendler' in f['properties']:
  14. continue
  15. else:
  16. print 'fetching', f['properties']['ID'], i
  17. pendlerParams['regionInd'] = f['properties']['ID']
  18. try:
  19. pendlerParams['type'] = 'ein'
  20. r = requests.get(pendlerUrl, params=pendlerParams)
  21. f['properties']['einpendler'] = json.loads(r.text)
  22. pendlerParams['type'] = 'aus'
  23. r = requests.get(pendlerUrl, params=pendlerParams)
  24. f['properties']['auspendler'] = json.loads(r.text)
  25. except KeyboardInterrupt:
  26. sys.exit(1)
  27. except:
  28. print 'errored at', i
  29. continue
  30. f = open('pendler.json', 'w')
  31. f.write(json.dumps(geojson))
  32. f.close()