Giter Club home page Giter Club logo

python-weather's People

Contributors

dependabot[bot] avatar igorechek06 avatar koebbe avatar manishankarconnect avatar null8626 avatar voltrexkeyva avatar wizpig64 avatar xcloudyunx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-weather's Issues

weather.current.sky_text languages

Is it possible to change the sky_text language output?
I was thinking that maybe is a feature of the API the library is utilizing and could be a great improvement if not yet implemented.

As for now I am translating to italian the result with "googletrans":

from googletrans import Translator
...
translator = Translator()
translator.translate(weather.current.sky_text, dest="it", src="en").text

A built in way to get directly the translated words would be much better

ValueError: 308 is not a valid WeatherType

Attempted to get the weather for the following location,

Puerto Ingeniero Ibáñez, Coihaique, Chile

  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\modal.py", line 187, in _scheduled_task
    await self.on_submit(interaction)
  File "C:\Users\ethan\source\repos\DiscordBot\BOT\_utils\modals.py", line 43, in on_submit
    weather = await Weather(self.children[0].value, self._typE)
  File "C:\Users\ethan\source\repos\DiscordBot\BOT\_utils\weather.py", line 7, in get_weather
    print(response)
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\forecast.py", line 645, in __repr__
    return f'<Weather current={self.current!r} location={self.location!r}>'
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\forecast.py", line 330, in __repr__
    return f'<CurrentForecast temperature={self.temperature!r} description={self.description!r} type=\'{self.type!r}\'>'
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\forecast.py", line 316, in type
    return WeatherType._new(int(self.__inner['weatherCode'])) # inspired by Rust <3
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\enums.py", line 54, in _new
    return WeatherType(num)
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "C:\Users\ethan\AppData\Local\Programs\Python\Python310\lib\enum.py", line 710, in __new__
    raise ve_exc
ValueError: 308 is not a valid WeatherType```

Error on non-English (German) Windows

Your Simple Usage example does not work as it is as await can only be used inside an async method!

I use the following code on a German Windows and get an error

import python_weather
import asyncio

async def main():
    client = python_weather.Client(format=python_weather.IMPERIAL)
    weather = await client.find("Washington DC")
    print(weather.current.temperature)
    for forecast in weather.forecast:
        print(str(forecast.date), forecast.sky_text, forecast.temperature)
    await client.close()

asyncio.run(main())
Traceback (most recent call last):
  File "c:\Users\markus\Downloads\test.py", line 12, in <module>
    asyncio.run(main())
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "c:\Users\markus\Downloads\test.py", line 6, in main
    weather = await client.find("Wien")
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\site-packages\python_weather\client.py", line 83, in find
    return Weather(content)
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\site-packages\python_weather\weather.py", line 53, in __init__
    self.current               = Forecast._current(data["current"])
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\site-packages\python_weather\forecast.py", line 47, in _current
    _class.date              = datetime.strptime(f'{data["@date"]} {data["@observationtime"]}', "%Y-%d-%m %H:%M:%S")
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\_strptime.py", line 577, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "C:\Users\markus\AppData\Local\Programs\Python\Python37\lib\_strptime.py", line 359, in _strptime
    (data_string, format))
ValueError: time data '2021-04-14 10:00:00' does not match format '%Y-%d-%m %H:%M:%S'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E699C74508>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001E699C87EB8>, 511227.875)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001E699C74408>

The default date format for a German Windows is %Y-%m-%d and not %Y-%d-%m.
That is why your code breaks.

City list

Hi
How can one know the city names available ? ( i.e Portuguese cities: Lisbon or Lisboa seems not to be available, Funchal is available).

Thks!
Nuno

weather results not updating

running the example.py at 2pm on Nov,13 2021 in Canada , getting the results that seems not updated:

26
2021-11-09 00:00:00 Clear 36
2021-11-10 00:00:00 Cloudy 33
2021-11-11 00:00:00 Cloudy 31
2021-11-12 00:00:00 Mostly Cloudy 43
2021-11-13 00:00:00 Sunny 38

Used to work well, what could be wrong?

The use of the package is not clear

Hi!

This package solves a real issue for me but I don't know how to use it, there's few information about it, the example runs ok. I'd like to change the metrics to Celsius and there's no information on how to do it and if it's possible to get the forecast of other cities or it works only for Washington?

Thanks

Still Learning need help. Can't make it work using py3

Hi
I can't seem to make this thing work.
I tried git clone https://github.com/vierofernando/python-weather.git
then ./setup.py
and i receive this as a wonderful helpfull message :-)

`from: can't read /var/mail/setuptools
./setup.py: line 2: syntax error near unexpected token `newline'
./setup.py: line 2: `setup('

I also tried
pip3 install python-weather
then copied the example and got this even more help...

Traceback (most recent call last):
  File "./watering_sys2.py", line 28, in <module>
    loop.run_until_complete(getweather())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "./watering_sys2.py", line 11, in getweather
    weather = await client.find("northam")
  File "/home/user/.local/lib/python3.8/site-packages/python_weather/client.py", line 83, in find
    return Weather(content)
  File "/home/user/.local/lib/python3.8/site-packages/python_weather/weather.py", line 53, in __init__
    self.current               = Forecast._current(data["current"])
  File "/home/user/.local/lib/python3.8/site-packages/python_weather/forecast.py", line 47, in _current
    _class.date              = datetime.strptime(f'{data["@date"]} {data["@observationtime"]}', "%Y-%d-%m %H:%M:%S")
  File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2021-05-16 20:00:00' does not match format '%Y-%d-%m %H:%M:%S'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fd3082be880>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fd30729d5e0>, 37511.072011544)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fd3082bedc0>

How do i fix it ?

Change language

Hello, first of all, thank you for your work!
The question is: Is it possible to change the language?

Thank you again!

How to convert time to normal view ?

When I use:

for forecast in weather.forecasts:
for hourly in forecast.hourly:
resp_msg += f'Time: {hourly.time}\n'
f'Temperature: {round((hourly.temperature - 32) / 1.8)}°C\n'
f'Description: {hourly.description}\n'
f'Type: {hourly.type}\n\n'

My bot returns:

Time: 0
Temperature: 17°C
Description: Partly cloudy
Type: Partly Cloudy

Time: 300
Temperature: 17°C
Description: Partly cloudy
Type: Partly Cloudy

Time: 600
Temperature: 16°C
Description: Partly cloudy
Type: Partly Cloudy

Time: 900
Temperature: 19°C
Description: Patchy rain possible
Type: Light Showers

How can I transform "Time" from 600 to 6:00?

Incorrect minimum Python version is specified

The := operator, which is available only in Python 3.8 and higher, is used here https://github.com/vierofernando/python-weather/blob/main/python_weather/rest.py#L25

However, the package defined the minimum Python version as 3.7 here https://github.com/vierofernando/python-weather/blob/main/setup.py#L34

Users on 3.7 will experience a SyntaxError. Either specify the minimum Python version as 3.8, or avoid using the := operator to maintain 3.7 compatibility.

Typo making 'current' object unusable

Hi, stumbled upon your python module today and wanted to use it. Whilst testing it out, I found that the 'current' object of the weather class cannot be used due to a small typo of current in the if statement located in 'response.py' line 160 return CurrentForecast(current) if currrent else None.

Thought I'd be better creating an issue rather than forking and creating a pull request for such a small thing.

Great work on the module, still going to use it!

All sky_text possibilities?

Can someone make a list of all the sky_text strings there are? I am making a program that uses it and need to know all of the texts.

print(forecast) returns AttributeError

for forecast in weather.forecasts: print(forecast)
returns the following error:
AttributeError: 'DailyForecast' object has no attribute 'temperature'

Trouble installing

Hi, I am pretty new to coding and wanted to use this for a project. I am using a raspberry pi4. I have downloaded the source distribution from pypi.org and extracted them to my downloads, but when I run $ pip install python-weather I get an error like this:
IOError: [Errno 2] No such file or directory: '/tmp/pip-build-( )/python-weather/setup.py' where inside of the ( ) is a random 6 letter/number code that changes every time I run it.
Any help would be appreciated.

Data sources?

I've been finding the temperature data to be inaccurate.

For example: New York City, NY's temperature (according to python-weather) is 66 degrees Fahrenheit (as of 3:47 PM on March 19th), while python-weather returns:

61 [CURRENT TEMPERATURE]
2022-03-18 00:00:00 Partly Cloudy 59
2022-03-19 00:00:00 Partly Sunny 56
2022-03-20 00:00:00 Cloudy 51
2022-03-21 00:00:00 Sunny 51
2022-03-22 00:00:00 Mostly Cloudy 47

As you can see, neither the current temperature nor the entry for today's date (March 19th) match the temperature readout from other sources, let alone each other.

Is this an issue with the data source?

Set days in forecast

Hello
Thank you for your great work! Im a highsctool teacher that will teach my students to use this project on their RPis.
I have a question. Is it possible to get more days than three in the forecast?
And I am sorry if this is not actually an issue, but I did not know any other way to reach you.
Regards, David in Sweden

Imperial request doesn't work

Copy and pasted exact code from example.py, all requests remain in metric. Conversion by myself is easy enough, but for clarity, I'm having issues

image

Here's my output:
image

Here is the actual temperature in Imperial from Weather.com
image

The MSN API is retired

Hi! Thanks for this library! I use it to figure out how often my watering system should turn on depending on the temperature forecast. This worked super well but now I noticed that it seemed to water them too often. When investigating, I found that running the code sample below I always get 2022-06-24 as the current date. Has something changed with the API that is used under the hood?

import python_weather
import asyncio
client = python_weather.Client()
weather = await client.find("Berlin, Germany")
weather.current.date
# datetime.datetime(2022, 6, 24, 18, 0)

Example Script ignores format and find

Plattfrom: Windows
Python Version: 3.9.5
Using your example code.

Issue:

  1. Script always defaults to IMPERIAL, even if METRIC is set.
  2. Script always defaults to location "Washington, DC", even if something else is set.

What I expect:
Example should make use of format=python_weather.METRIC if set
Weather should be fetched for the specific location with client.find

I downloaded python-weather via pip. Maybe its a old version?

Temperature is incorrect and with/without state produces different results

I'm getting wildly inaccurate temperatures and I cannot pinpoint why. I thought it was because the city was obscure/smaller, but even for some larger cities, it's way off.

Here's some sample code:

import python_weather
import asyncio
import os
import sys
import re
from uszipcode import SearchEngine

async def getweather(place):
  async with python_weather.Client(format=python_weather.IMPERIAL) as client:

    weather = await client.get(place)
    print(weather.current.temperature)
    print(weather.current.description)

if __name__ == "__main__":
    city = sys.argv[1]
    place = city

    if re.match(r'^\d{5}', city):
        engine = SearchEngine()
        zipcode = engine.by_zipcode(city)
        city = zipcode.major_city
        state = zipcode.state
        place = f"{city}, {state}"

    asyncio.run(getweather(place))

Output for "Folsom, CA":

% ./w.py "Folsom, CA"
75
Sunny

weather.com reports sunny and 82 and accuweather 85, so 75 seems way off. Even for Atlanta, GA it's off:

% ./w.py "Atlanta, GA"
74
Partly cloudy

weather.com reports partly cloudy and 78, and accuweather 79.

Note that I'm not even using the zip code lookup. I've also tried without the state with different (but also inaccuate) results:

% ./w.py Atlanta
71
Partly cloudy

Here's the version I'm using with Python 3.9:

% /usr/bin/python3.9 -c 'import python_weather; print(python_weather.version)'
0.4.1

Thanks,
Josh

when passing in to the function different locations nothing returns.

i ve been trying to make a weather function for my discord application using python weather but every time i pass a different city other than : "Bucharest" or "Washington DC" . The following comes up.
image
i ve tried looking up the errors and nothing seems to work really. i dont know if this is an actual bug or me just being dump.
for reference this is the script i wrote:

import python_weather
import asyncio
class WeatherFunc:
    def __init__(self,location):
        self.client = python_weather.Client(format=python_weather.METRIC)
        self.location = location


    async def on_call(self):
        weather = await self.client.find(self.location)
        print(weather.current.temperature)



        await self.client.close()
object1  = WeatherFunc("Sofia")
if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(object1.on_call())

if by any chance i am wrong sorry for addressing my issue and please tell me what i should change.

Question

Is someone able to make a file that makes use of everything this can do? There's certain things I want to do with it but I wouldn't really know how (and I'm sorta new to Python, so it'd be hard to try and figure what it can do out myself)

Cant use if you ever forgot to close client

I got an error message before I was able to close the client and now when ever I try to make another client I get this error message(btw I am using discord.py):
`Ignoring exception in command weather:
Traceback (most recent call last):
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line
85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\ianlo_btxmkkk\visualstudio\botstf\bot.py", line 64, in weather
weather = await client.find(city)
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\client.py", line 37,
in find
return await self.http.request(location)
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\python_weather\rest.py", line 24, in request
parsed = parse(self.cache[url])
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\xmltodict.py", line 378, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line
863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\ianlo_btxmkkk\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line
94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ExpatError: not well-formed (invalid token): line 1, column 0
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E846501960>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001E8465448E0>, 850371.0)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001E846501990>`

Edit:

MY CODE:

@bot.command()
async def weather(ctx, city="Austin TX"):
client = python_weather.Client(format=python_weather.IMPERIAL)
weather = await client.find(city)
await ctx.reply(f"The current tempature in {city} is {weather.current.temperature}.")
await client.close()

Sky_text aint working

image
I don't really get the reason because of which the "sky_text" aint working .

P.S i am very new to programming and codding.

weather forecast is not updating

Hi null8626,

Thank you for providing this tool. The weather forecast is not updating. the dates keep unchanged between July 19- July 24. Could you please have a check?

Thank you!
Daniel

Api stopped working a few weeks ago

A few weeks ago i started having this error messages while trying to use the api. I did not change my code at all.

Traceback (most recent call last): File "C:\venv\lib\site-packages\python_weather\client.py", line 83, in find return Weather(content) File "C:\venv\lib\site-packages\python_weather\weather.py", line 53, in __init__ self.current = Forecast._current(data["current"]) File "C:\venv\lib\site-packages\python_weather\forecast.py", line 47, in _current _class.date = datetime.strptime(f'{data["@date"]} {data["@observationtime"]}', "%Y-%d-%m %H:%M:%S") File "C:\AppData\Local\Programs\Python\Python39\lib\_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "C:\AppData\Local\Programs\Python\Python39\lib\_strptime.py", line 349, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '2021-05-28 13:00:00' does not match format '%Y-%d-%m %H:%M:%S' Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x000002881BCCF580> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000002881BCCCB20>, 437676.25)]'] connector: <aiohttp.connector.TCPConnector object at 0x000002881BCCF550>

Debian specific requirements for your docs

Just a reminder for your docs: with Debian I needed to
sudo apt install python3-xmltodict and sudo apt install python3-aiohttp in order to run your example at this date.

Problem with forecasts

I make the weather bot in telegram. There are 5 buttons, 2 are forecasts (Hourly_forecasts and Daily_forecasts). When I click one of 2 buttons It displays what I need, but when I click another forecasts It return error.
Photo of clicking forecasts button:

photo_5271836120210065227_y
photo_5271836120210065230_y
photo_5271836120210065232_y

Errors:

изображение_2022-12-22_172030819
изображение_2022-12-22_173833556

And 3 rest buttons click as much as I want:

photo_5271836120210065225_y
photo_5271836120210065226_y

Is that API problem or Bot problem ?

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.