Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.3.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
14 changes: 10 additions & 4 deletions watttime/api.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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:
Expand Down