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

get_data.py 1.2 KB

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
35
36
37
38
39
40
41
42
43
  1. """Download a copy of the CAISO curtailment data.
  2. Oversupply data can be found at the following URL:
  3. https://www.caiso.com/informed/Pages/ManagingOversupply.aspx
  4. """
  5. import requests
  6. from pathlib import Path
  7. from loguru import logger
  8. from urllib.parse import urlparse
  9. from src.conf import settings
  10. OUTPUT_DIR = settings.DATA_DIR / "raw/caiso/"
  11. base_url = "https://www.caiso.com/Documents/{}"
  12. def generate_urls():
  13. """Generate a set of URLs for each year of data in the analysis period.
  14. """
  15. yield base_url.format("ProductionAndCurtailmentsData-May1_2014-May31_2017.xlsx")
  16. yield base_url.format("ProductionAndCurtailmentsData-Jun1_2017-Dec31_2017.xlsx")
  17. for year in range(2018, 2021):
  18. yield base_url.format(f"ProductionAndCurtailmentsData_{year}.xlsx")
  19. def main():
  20. for url in generate_urls():
  21. logger.info("Downloading CAISO Curtailment file at: {url}", url=url)
  22. fn = Path(urlparse(url).path).name
  23. with requests.get(url) as response:
  24. response.raise_for_status()
  25. fp = OUTPUT_DIR / fn
  26. with open(fp, "wb") as fh:
  27. for chunk in response.iter_content():
  28. fh.write(chunk)
  29. if __name__ == "__main__":
  30. OUTPUT_DIR.mkdir(exist_ok=True)
  31. main()
Tip!

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

Comments

Loading...