Giter Site home page Giter Site logo

carbonintensity's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

carbonintensity's Issues

Change time string from Z to +00:00

Is your feature request related to a problem? Please describe.

There is a known 'feature' with python and DateTime strings in that python cannot decode the 'Z' as a timezone. This is because the fromISO method is the inverse of the ToISO method which does not handle 'Z'. https://bugs.python.org/issue35829 refers.

Javascript does handle it correctly as does PHP.

Describe the solution you'd like

Replace 'Z' in the DateTime Strings from the API to '+00:00'. Python can then convert this to a Unix Timestamp else it may treat it as a local time.

https://discuss.python.org/t/parse-z-timezone-suffix-in-datetime/2220 refers

Describe alternatives you've considered

Additional context

Date not updating when calling async_get_data

Describe the bug
The date is not updating when calling method async_get_data. The issue is related on how we set up the default value for from_time in the function:

class Client:
"""Carbon Intensity API Client"""
def __init__(self, postcode):
self.postcode = postcode
self.headers = {"Accept": "application/json"}
_LOGGER.debug(str(self))
def __str__(self):
return "{ postcode: %s, headers: %s }" % (self.postcode, self.headers)
async def async_get_data(self, from_time=datetime.now()):
request_url = (
"https://api.carbonintensity.org.uk/regional/intensity/%s/fw24h/postcode/%s"
% (from_time.strftime("%Y-%m-%dT%H:%MZ"), self.postcode)
)
_LOGGER.debug("Request: %s" % request_url)
async with aiohttp.ClientSession() as session:
async with session.get(request_url) as resp:
json_response = await resp.json()
return generate_response(json_response)

In Python the value of the default paramters are calculated at definition time.

  • Change default parameter to None and handle the value in the function body.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.