Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ca_powerplants.py 805 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  1. """
  2. Pulls in data from california powerplants.
  3. Source: https://cecgis-caenergy.opendata.arcgis.com/datasets/california-power-plants
  4. """
  5. import json
  6. import requests
  7. from src.conf import settings
  8. DATA_DIR = settings.DATA_DIR
  9. output = DATA_DIR / "raw/geography/powerplants.geojson"
  10. uri = "https://opendata.arcgis.com/datasets/4a702cd67be24ae7ab8173423a768e1b_0.geojson"
  11. class UnexpectedData(Exception):
  12. pass
  13. if __name__ == "__main__":
  14. r = requests.get(uri, stream=True)
  15. with open(output, "wb") as fh:
  16. for chunk in r.iter_content(chunk_size=1024*5):
  17. if chunk:
  18. fh.write(chunk)
  19. # Validate the data
  20. with open(output, "r") as fh:
  21. try:
  22. data = json.load(fh)
  23. except Exception as e:
  24. raise UnexpectedData(e)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...