topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday June 22, 2021, 10:08 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Display the weather in the command line (Weather forcast to text)  (Read 1313 times)

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
What I want: To display the weather from www.klart.se in the command line.

From this page https://www.klart.se...4der-alberga/timmar/
I want a program that gets the today weather forcast part (part marked in screen shot 1) and saves it to a textfile so it can be typed into into a command line window, or directly types it into the command line window (see screen shot 2).
Note that I changed some tittles in the command line version.
The text on the webpage is in Swedish, I hope it is not a problem.

Picture1.pngDONE: Display the weather in the command line (Weather forcast to text)Picture2.pngDONE: Display the weather in the command line (Weather forcast to text)
« Last Edit: June 13, 2021, 06:34 PM by user45454 »

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
What I want: To display the weather from www.klart.se in the command line.

From this page https://www.klart.se...4der-alberga/timmar/

Hi! I'm currently finishing several "dangling" releases yet yours gets included as well since it's a 1-day code :)

https://github.com/p...main/weather-to-text
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 10,907
    • View Profile
    • Donate to Member
So, this isn't exactly what you asked for, but it was an interesting problem, so I did it anyway :)

It uses wttr.in (I couldn't figure out that other site- when I put in a location, it required a more specific name for the results page than I could figure out quickly).

It's in powershell, and I documented it in the comments. Save it to Get-Weather.ps1 and run it, i.e.

.\Get-Weather.ps1

It will prompt you for the city- you can specify it just by city and it will sometimes get it right from your location, but you can also use state/province/country, etc - just separate with ,. i.e.

.\Get-Weather.ps1
Enter name of the City to get weather report: Cairo

This would display the weather for Cairo,Egypt, but

.\Get-Weather.ps1
Enter name of the City to get weather report: Cairo,Illinois

Would display the weather for Cairo,Illinois

Code: PowerShell [Select]
  1. <#
  2. Get-Weather
  3.  
  4. Created in response to a request on DonationCoder
  5. - https://www.donationcoder.com/forum/index.php?topic=51394
  6.  
  7. Retrieves weather from http://wttr.in/ and prints it to commandline
  8.  
  9. Parameters:
  10. -City: [required] City to retrieve the weather for
  11. -IncludeTomorrow : Also include tomorrow's weather
  12. -IncludeNext2Days : Also include the weather for the next two days
  13.  
  14. #>
  15.  
  16. param (
  17.     [string]$City = $( Read-Host "Enter name of the City to get weather report" ),
  18.     [switch] $IncludeTomorrow,
  19.     [switch] $IncludeNext2Days
  20.     )
  21.  
  22. try {
  23.     $url = "http://wttr.in/$($City)"
  24.  
  25.     $Weather = $(Invoke-WebRequest $url –UserAgent curl).content -split "`n"
  26.  
  27.     if($Weather)
  28.     {
  29.         $Weather[0..16]
  30.         if(($IncludeTomorrow) -or ($IncludeNext2Days)){ $Weather[17..26] }
  31.         if($IncludeNext2Days){ $Weather[27..36] }
  32.     }
  33. }
  34. catch {
  35.     $_.exception.Message
  36. }

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
So, this isn't exactly what you asked for, but it was an interesting problem, so I did it anyway :)

Wowie!!! Thanks for your willingness to help a fellow!



Note that I changed some tittles in the command line version.

WeatherToText v0.1.0 is released: https://www.donation...ex.php?topic=51403.0

Text substitution comes @ v0.1.1

Please check what's there suits you Cheers!
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: May 15, 2021, 08:05 AM by publicdomain »

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
So, this isn't exactly what you asked for, but it was an interesting problem, so I did it anyway :)

Wowie!!! Thanks for your willingness to help a fellow!



Note that I changed some tittles in the command line version.

WeatherToText v0.1.0 is released: https://www.donation...ex.php?topic=51403.0

Text substitution comes @ v0.1.1

Please check what's there suits you Cheers!
-publicdomain (May 15, 2021, 07:55 AM)

Verry nice but I get this error
"Error: The request was aborted: Could not create SSL/TLS secure channel."

 :o

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
"Error: The request was aborted: Could not create SSL/TLS secure channel."

Thanks for reporting, I tested it on Linux/Mono version 6.12.0.122 (.NET framework 4.5 compilation target).

Going to add text replacements & test it on Windows for patched v0.1.1 :Thmbsup: Cheers!

WeatherToText_v0-1-0.pngDONE: Display the weather in the command line (Weather forcast to text)

♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: May 16, 2021, 03:01 AM by publicdomain »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 10,907
    • View Profile
    • Donate to Member
I just realized looking at the source, I was reading too much into the request- you wanted that specific page, not a parameterized query from that site.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
Fixed the cross-platform code from the report:

"Error: The request was aborted: Could not create SSL/TLS secure channel."

v0.1.1 has been released! :)

WeatherToText topic updated to reflect it: https://www.donation...ex.php?topic=51403.0

Tested on Windows & Linux. Both running:

WeatherToText_v0-1-1_Windows.pngDONE: Display the weather in the command line (Weather forcast to text)

WeatherToText_v0-1-1_Linux.pngDONE: Display the weather in the command line (Weather forcast to text)

Cheers! :Thmbsup:
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: May 16, 2021, 03:32 AM by publicdomain »

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
Hi,

A short translation of what the Swedish words mean.


Tid=Time
Känns=Feels (känns som=feels like)
BY = Gust of wind (should say "vindby" because vind=wind)
Sannolikhet nederbörd =  Probability of precipitation
Sannolikhet åska = Probability of thunder
Soluppgång = Sun Rise
Solnedgång = Sun set

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
Fixed the cross-platform code from the report:

"Error: The request was aborted: Could not create SSL/TLS secure channel."

v0.1.1 has been released! :)

WeatherToText topic updated to reflect it: https://www.donation...ex.php?topic=51403.0

Tested on Windows & Linux. Both running:

Picture3.pngDONE: Display the weather in the command line (Weather forcast to text)

[ Invalid Attachment ]

Cheers! :Thmbsup:
-publicdomain (May 16, 2021, 03:06 AM)

Things are really starting to take form.
Looking good :-)
Is it possible to make it look like picture provided?
No borders, removed "(by)" more compact with row separtion for "nederbörd" & "åska" and no letter "A" after the temp.
Picture3.pngDONE: Display the weather in the command line (Weather forcast to text)

For future release
If the weather location could be made as an input like this
"WeatherToText.exe https://www.klart.se...4der-alberga/timmar/"
"WeatherToText.exe https://www.klart.se...4der-caracas/timmar/"
It would be usable for alot more people.

Right now it is hardcoded so the program is only usable for about the 100 people
that lives in my small town. :-)


wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 10,907
    • View Profile
    • Donate to Member
For future release
If the weather location could be made as an input like this
"WeatherToText.exe https://www.klart.se...4der-alberga/timmar/"
"WeatherToText.exe https://www.klart.se...4der-caracas/timmar/"
It would be usable for alot more people.


Yeah, this was what I was trying to do, but couldn't figure out the API for the urls, it being Swedish limited my ability to search. Your suggestion of sending in the URL is a good one!

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
Is it possible to make it look like picture provided?

Yes afirmar.gif

For future release [...]

Sure thing! :up:

I'm coding AppFolderIcon + a couple other proggies for the community simultaneously; this update is added to the flow of releases  :)

(Stay tuned! We're talking days only)
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: May 19, 2021, 05:33 PM by publicdomain »

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
WeatherToText v0.2.0 is out! porra.gif

Download + info: https://www.donationcoder.com/forum/index.php?topic=51403.0

Cross-platform:

WeatherToText_v0-2-0_screenshot_2.pngDONE: Display the weather in the command line (Weather forcast to text)
Windows

WeatherToText_v0-2-0.pngDONE: Display the weather in the command line (Weather forcast to text)
Linux

Enjoy! dedosarriba.png
Vic
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: May 20, 2021, 07:13 AM by publicdomain »

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
WeatherToText v0.2.0 is out! [ Invalid Attachment ]

Download + info: https://www.donationcoder.com/forum/index.php?topic=51403.0

Cross-platform:

[ Invalid Attachment ]
Windows

[ Invalid Attachment ]
Linux

Enjoy! [ Invalid Attachment ]
Vic
-publicdomain (May 19, 2021, 05:16 PM)


This is looking real great now!  :up: :D

Just a few things.
Picture 1:Picture4.pngDONE: Display the weather in the command line (Weather forcast to text)
1) You can see in the picture that I get an "Â" between the numer and the grade sign.
2) And the sunset is getting the "Å" letter wrong, "21:34 SolnedgÃ¥ng".
At the time of writing Sun rise is gone but I think sun rise aka "Soluppgång" was correct, "åska" and "nederbörd" is also working fine.


Picture2:Picture5.pngDONE: Display the weather in the command line (Weather forcast to text)
1) I would  like to have the whole part that is in between the "()" removed.
See picture two what I mean.
2) It looks like the program forcing yellow ouput ?
We dont need to do that, some day we might want to change output color.
« Last Edit: May 21, 2021, 02:31 PM by user45454 »

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
This is looking real great now!

Please check v0.3.0: https://www.donation....msg445163#msg445163

:Thmbsup:
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 14
    • View Profile
    • Donate to Member
This is looking real great now!

Please check v0.3.0: https://www.donation....msg445163#msg445163

:Thmbsup:
-publicdomain (June 10, 2021, 12:20 AM)


Could we add the option to load also tomorrows forcast ?
The data is on the same site to be read.
Im running this at home, reloading once an hour, works great!  :up:
But the later it gets the more I would like to see whats happens after midnight.

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 266
  • Call me Vic!
    • View Profile
    • PublicDomainDaily.com
    • Read more about this member.
    • Donate to Member
Could we add the option to load also tomorrows forcast ?

Yes, sure! :) What do you have in mind? Extra parameter added to the program? (i.e. for passing "tomorrow" as argument).

It can also be integrated into regular operation, perhaps having 24-hour data always displayed on screen (regardless of day boundaries).

Fell free to express! I'm here to code it :up:

Vic
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor