diff --git a/.VERSION b/.VERSION new file mode 100644 index 0000000..ea7786a --- /dev/null +++ b/.VERSION @@ -0,0 +1 @@ +v1.3.3 diff --git a/setup.py b/setup.py index 25977d6..ed5a3e5 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ description="An officially maintained python client for WattTime's API providing access to electricity grid emissions data.", long_description=open("README.md").read(), long_description_content_type="text/markdown", - version="v1.3.3", + version=open(".VERSION").read().strip(), packages=["watttime"], python_requires=">=3.8", install_requires=["requests", "pandas>1.0.0", "holidays", "python-dateutil"], diff --git a/watttime/api.py b/watttime/api.py index 8be1113..0a208de 100644 --- a/watttime/api.py +++ b/watttime/api.py @@ -1,19 +1,22 @@ import os -import time import threading import time -from datetime import date, datetime, timedelta, time as dt_time from collections import defaultdict +from concurrent.futures import ThreadPoolExecutor, as_completed +from datetime import date, datetime +from datetime import time as dt_time +from datetime import timedelta from functools import cache from pathlib import Path from typing import Any, Dict, List, Literal, Optional, Tuple, Union -from concurrent.futures import ThreadPoolExecutor, as_completed import pandas as pd import requests from dateutil.parser import parse from pytz import UTC +VERSION = open(".VERSION").read().strip() + class WattTimeBase: url_base = os.getenv("WATTTIME_API_URL", "https://api.watttime.org") @@ -106,7 +109,10 @@ def _login(self): self.token_valid_until = datetime.now() + timedelta(minutes=30) if not self.token: raise Exception("failed to log in, double check your credentials") - self.headers = {"Authorization": "Bearer " + self.token} + self.headers = { + "Authorization": "Bearer " + self.token, + "User-Agent": f"watttime-python-sdk-{VERSION}", + } def _is_token_valid(self) -> bool: if not self.token_valid_until: