linuxmint / cinnamon-spices-desklets

Desklets for the Cinnamon desktop
http://cinnamon-spices.linuxmint.com
138 stars 156 forks source link

bbcwx@oak-wood.co.uk: Feature Request #1042

Closed LinuxMint20 closed 7 months ago

LinuxMint20 commented 7 months ago

Desklet name and maintainer

bbcwx@oak-wood.co.uk @tipichris

What would you like to see?

Chris, if you aren't going to update Weather Desklet with the changes needed, then I suggest fork the project to someone who is better equipped to maintaon it. Please understand I am not judging or chastising you, I know that you have many projects in the works and life just sometimes get in the way. It's just that the weather underground api has changed, several other services aren't working correctly according to the comments on the desklets' cinnamon spices page, and we have as yet been unable to reach you or access a working website (the link leads to an old page on your website). Please, PLEASE update the app and contact info or turn it over to another programmer, or the Linus Mint dev team.

Thank you, sir.

rcalixte commented 7 months ago

For what it's worth, I've taken a look at this. The main challenge is that a number of the API endpoints that were in use have been deprecated or severely limited their free tiers. On top of that, each API has its own implementation details and limitations/features, meaning it isn't as trivial as adding a new data service to the list in the interface and just having it working. A lot of code needs to be written per data service.

For my current purposes, I use the Open Weather Map Free with an API key that I generated with a free account. This is working across a few machines for me.

Given that the desklet is in the public repository, anyone can open pull requests for it. I would only think a fork would be necessary if there were drastic changes. For the continuation of the existing desklet, a fork isn't necessary. I've personally compiled a list of endpoints I would like to implement at some point but as I mentioned, I have a working solution that fits my needs, pushing that task further down my own backlog.

Are there any urgent items you think should be addressed? Should non-working services be removed from the settings page for now? I'll take a look at the comments from the Spices page too to see if there is anything actionable in the short-term. (EDIT: It looks like the Wunderground API was updated at some point and the API calls in the desklet need to be updated for it. I can take a look to see if this can be solved in the short-term.)

LinuxMint20 commented 7 months ago

@rcalixte, I'm grateful both for your prompt reply and that someone has taken a look at this. I think non-working services should absolutely be removed, if they cannot be updated (essentailly, deprecated). In addition to Weather Underground, there was someone who posted a comment on the Cinnamon Spices Weather Desklet website about meteoblue approximately 3 weeks ago, as well. To that end, I have contacted the dev team at Weather Underground. The address (api url) that the Weather Desklet now needs to connect to is for us personal users is

https://api.weather.com/v2/pws/observations/current?stationId=MyStationID&format=json&units=e&apiKey=MyApiKey,

where MyStationID=Your current weather station on Wunderground.com (or the location for standard users, those without a weather station), and units=units of measure, e for english units, m for metric, and hybrid is UK or elsewhere, and naturally MyApiKey being the api that you enter into the field in WU settings in the config settings as per the following document:

https://docs.google.com/document/d/1KGb8bTVYRsNgljnNH67AMhckY8AQT2FVwZ9urj8SWBs/edit .

Here is a link to the main documentation. https://docs.google.com/document/d/1eKCnKXI9xnoMGRRzOL1xPCBihNV2rOet08qpE_gArAY/edit .

I have been altering the code in the desklet.js document in the spices folder. I write scripts, but I'm patently unable to write javascript code. If there is a way to make this work, I would be eternally appreciative. This project has cost me dozens, if not more, of hours of frustration, and embarassment at practically being laughed at and minimized on coding support sites, none of which I shall name here.

Thank you so much for your interest in this invaluable project, and I hope you can do something with the changes that need to occur.

tipichris commented 7 months ago

As you've worked out, I no longer have time to maintain this desklet. Perhaps if the service I use (BBC) stopped working I might make an effort to get it going again, but from my perspective it works fine, so I have little incentive to work on it :)

I agree with @rcalixte, it doesn't need forking in order for others to do some work on it. In fact, from my perspective it is already forked, since it began life at https://github.com/tipichris/bbcwx. Anyone can create a pull request.

Again, @rcalixte is correct, each API endpiont is different. The desklet itself implements a consistent API internally, and uses what are in effect drivers to translate between that and the different endpoints. The consistent internal handling requires the drivers to return values in specific units, as per the comments in the script. So ideally an endpoint should return the units the desklet expects. The desklet will then convert these to the units you want to see.

// Distance: km // Speed: km/h // Temperature: C // Pressure: mb / HPa // Visibility may be expressed either as a number of km or a descriptive string // Wind direction should be a 16 point compass bearing, eg SSW // Day names should be English three letter abbreviations, eg Mon, Tue

Beyond that it's so long since I've looked at that I can't really remember what's needed. And I barely ever code in javascript these days, so I doubt I could update it even if I had the time :)

LinuxMint20 commented 7 months ago

Thank you, Chris. I completely understand. I was simply unaware of the inherent difference between a fork and a pull. I hope someone takes up the mantle from you. It's a brilliant piece of software :)

My hat's off to you, sir.

rcalixte commented 7 months ago

As I consider this desklet a staple of how I customize Cinnamon, I certainly don't mind taking some time over the next week or two to see what quick fixes can be implemented. I'm unclear about taking on a formal role as maintainer for the desklet but that isn't too relevant right now as long as it gets back to a satisfactory state for end users. I have an arrangement like this for a few other desklets and applets already. As long as I'm using them, they won't fall too far off. 😅

Thanks for opening this Issue @LinuxMint20! Things can certainly get lost on the Spices website otherwise.

LinuxMint20 commented 7 months ago

@rcalixte, I cannot thank you enough. And I appreciate your thanks in my opening this issue, it absolutely had to happen.

As I stated before, I believe it was in my initial post, I am just a humble ol' script kiddie and certainly NOT a programmer. Ergo, I have filled the desklet.js file with just so much "spaghetti code." That being said, I would be more than willing to share with you my copy of the document in the hope that it may make your task that much easier, or perhaps give you some new idears you might not arrive at otherwise. Should that be the case, I apologize in advance for the state of the code :)

rcalixte commented 7 months ago

The notes and links you've provided are more than sufficient. I would encourage you to keep at it though. The reason I hadn't jumped at this desklet like I have on others (other than finding a working function) is because it is slightly more complex, due to what amounts as drivers as Chris mentioned earlier. I hadn't even touched JavaScript much in almost a decade before jumping in a little over a year ago. Other desklets or applets can prove a better learning ground than this one so don't be discouraged! Just keep at it!

LinuxMint20 commented 7 months ago

@rcalixte, I appreciate it :) I'll continue the fight ;)

tipichris commented 7 months ago

Let me try and briefly summarise how the drivers work.

The desklet initiates the driver as this.service. Each driver extends wxDriver, which contains various functions that may be useful, and, crucially, the data structures. The [driver].capabilities object describes the capabilities of the current driver. [driver].capabilities is generally just defined when the driver is initialised and it doesn't change. The prototype wxDriver sets all values to true, so in an individual driver it is only necessary to override the capabilities the driver doesn't have with a false.

wxDriver._emptyData() creates a [driver].data object that will contain all the data to be displayed. The structure is there, but no data.

The main desklet will periodically call [driver].refreshData(). This is really the only function the driver is required to have.

refreshData() takes as a single argument the desklet object itself, so that it is able to call functions in the desklet - i.e. it is called from the desklet object as this.service.refreshdata(this)

The job of refreshdata() is to connect to the api endpoint, grab the data from it, parse it, populate the [driver].data object and then call the main desklet's functions displayCurrent(), displayForecast() and displayMeta() (this is why it is passed the desklet object as an argument).

The data in the [driver].data object needs to be in a consistent form. The comments above wxDriver._emptyData() give some clues

// create an empty data structure to be filled in by child drivers // numeric data returned should be values without units appended. The following units // should be used // Distance: km

// Speed: km/h // Temperature: C // Pressure: mb / HPa // Visibility may be expressed either as a number of km or a descriptive string // Wind direction should be a 16 point compass bearing, eg SSW // Day names should be English three letter abbreviations, eg Mon, Tue

What's missing from that is that data.cc.icon should be a string which is basically a two digit code identifying an icon to be displayed to summarise current conditions. You can find a hint on this in https://github.com/tipichris/bbcwx/wiki/Icon-code-meanings

That's about it. Everything else is just how you grab the data from the api endpoint and turn it into the data in [driver].data (which the main desklet sees as this.service.data). Good luck!

LinuxMint20 commented 7 months ago

@tipichris, thank you again. I had tp reread your reply several times to decipher it, but I believe I have the gist. @rcalixte, the thing in particular I would like to address for my issue is where Chris exclaimed, "The job of refreshdata() is to connect to the api endpoint, grab the data from it, parse it, populate the [driver].data object and then call the main desklet's functions displayCurrent(), displayForecast() and displayMeta() (this is why it is passed the desklet object as an argument)."

Before I address that, however, i would just like to take a sec to thank you, from the bottom of my heart, to inspire me to continue chasing this. I figured out the syntax of the code and the weather desklet connected! I actually accomplished this a scant two minutes before your reply, Chris. I am excited beyond...well, you guys get the point. I had already planned to leave this in your more than capable hands, Rick, until you convinced me otherwise.

But anyway, my question is this; Rick, might you able to connect to the api endpoint, grab the data from it, parse it, and populate it using the links to the documents up above?

rcalixte commented 7 months ago

Before I address that, however, i would just like to take a sec to thank you, from the bottom of my heart, to inspire me to continue chasing this. I figured out the syntax of the code and the weather desklet connected!

"A journey of a thousand miles begins with a single step."

Everyone started at the same place since none of us (to my knowledge 😅) were coding in the womb. Congrats on that "it works!" feeling. A note, it doesn't ever get old.

But anyway, my question is this; Rick, might you able to connect to the api endpoint, grab the data from it, parse it, and populate it using the links to the documents up above?

It looks like it. Based on what I've seen there, plus looking at the code, plus the overview from Chris, there's more than enough to get this done, minus the immediate time. I hadn't remembered it right away but I had done two other modifications to the desklet before to address some functionality, cleanup, and whatnot. Knowing me, I likely held off on doing the larger scoped changes (and tucking them further down my backlog) since there was enough core functionality for the desklet to work for my needs. I only wish I had taken a look at the Spices page as a few of those issues could have been addressed. Nonetheless, we're in good shape here. Let me know if you want to take a shot and I can hold off. Most likely, I might not be able to get to this until around next week or so but I am excited to get these things sorted since I think the community will appreciate it.

LinuxMint20 commented 7 months ago

I also believe the community will appreciate it. Heck, i LOVE it! I have since moved on to trying to restyle the settings-schema.json to tweak the look of the desklet, albeit with the changes not updating (I think the app is definitely drawing from another file, I just need to find it). I would love to take a shot, but I don't have either of your experience with coding and I think it would ultimately be an egregious waste of time while the community waits for a functioning desklet, so I therefore elect to leave in your more than capable hands. Thank you, though, for the offer. You are truly a kind soul. If we have to wait until a week or so from now, then so be it. It'll be worth the wait!

I am SO pumped.

rcalixte commented 7 months ago

Small update. I won't lie, this is rather unpleasant. 😅

These APIs are quite terrible to work with. My biggest frustration is the barrier it takes to get to an API key. I refuse to attempt to implement something on a hope and a prayer but they make it unwieldy to even get a basic API key. If I can't test the code for that service, I'm not going to ship any implementation for that service. This is why I'd originally decided on implementing new endpoints entirely but pushed it further back in my backlog due to what that would require too. Venting aside, there are services that aren't awful and there are at least two that I think are reasonable to implement.

Where I'm uncertain is how attached people are to a particular service. If it needs to be a specific service and that service is too difficult to develop for, I don't know how to resolve that impasse personally. Someone with enough interest and access to an API key would need to step up and effectively maintain the code for the driver for that service.

Long-term, I would prefer to have services that aren't hostile towards users and/or developers.

In the short-term, I've gone through the other open Issues for this desklet and picked a few that I thought would be good to implement too. On top of that, I've removed the services that were labeled as deprecated since they don't work and won't work again. For the services that just don't work for me, I can't test if that's because of not having an API key or if something within the API has changed itself (minus the API you provided the documentation for where I know the API changed and I just can't access it). I'm inclined to leave these unchanged so that another aforementioned volunteer can have something of easier access to a base to work with. There aren't a lot of options here which in itself is rather frustrating.

Okay, maybe not so small of an update. 😅

LinuxMint20 commented 7 months ago

Rick, my friend, as far as my issue goes, walk away. I am truly sorry. I applaud your effort, by the way. I personally thank you for looking at it and communicating so clearly, and so often. Maybe in the future, a proper fork can be created from this unholy mess. Something made for WU for those of us who have pws and aren't only enthusiasts. Whilst not optimistic, I shall continue talking to the WU dev team. Mayhap one day something will come to fruition. In the meantime, Im excited to see the results of your labor :) Thank you again, sir.

rcalixte commented 7 months ago

Rick, my friend, as far as my issue goes, walk away. I am truly sorry. I applaud your effort, by the way. I personally thank you for looking at it and communicating so clearly, and so often.

No need to apologize! I'm far too stubborn to give up but venting a bit actually helped clear my mind. I'm going to refactor quite a bit with the goal of making future maintenance much easier.

Maybe in the future, a proper fork can be created from this unholy mess. Something made for WU for those of us who have pws and aren't only enthusiasts. Whilst not optimistic, I shall continue talking to the WU dev team. Mayhap one day something will come to fruition.

There's still no need to fork the desklet, especially when a lot of the code will just be duplicated. Once refactored, it should hopefully be more approachable should someone with valid credentials be able to step up, even you!

In the meantime, Im excited to see the results of your labor :) Thank you again, sir.

Thank you for the kind words and the support! I'm anxious to get this shipped soon. 😅

rcalixte commented 7 months ago

Okay, much better update this time. I have a working refactor. I need to do some code cleanup and probably some logical improvements but other than that, we can move forward. I anticipate a few more days of development and bug checking but I think this is reasonable to get pushed out maybe some time next week.

This is back to being pleasant again. 😅

LinuxMint20 commented 7 months ago

This literally made my day :)

rcalixte commented 7 months ago

@LinuxMint20 @tipichris I'm finalizing testing on my end and updating the documentation and whatnot. I think this is ready to go. Will either of you have a chance to test if we go live either tomorrow or the day after? I'd like to get some initial testing done just in case there are some bugs I've missed. In general, it's looking fantastic so I'm not terribly worried but you never know.

LinuxMint20 commented 7 months ago

@rcalixte Im ready. Just installed it on the new laptop today, in fact.

rcalixte commented 7 months ago

@rcalixte Im ready. Just installed it on the new laptop today, in fact.

I'll try to shoot for tomorrow then. I'm mostly putting together an updated README at this point so I might just get the main things in there and wait for feedback. Will you have the ability to test any of the services you provided documentation for?

LinuxMint20 commented 7 months ago

Not as yet, not with wunderground, but theres always open weather :)

rcalixte commented 7 months ago

Not as yet, not with wunderground, but theres always open weather :)

I'm going to go ahead and merge the pull request now. It will be the update in Desklets on your system. I've noted it in the README, but you may need to restart Cinnamon after the upgrade. (It's such a significant change from the previous version that I thought about forking it multiple times but I think this restart is the only potential disruption to expect despite all the changes.)

LinuxMint20 commented 7 months ago

@rcalixte Fantastic job! I was looking over the code in desklet.js in 3.0 and 5.4. REALLY impressive, man. The only issue is the syntax of the apiurl. It should be baseurl+stationid+format+apikey. Your syntax reversed the apikey and format is at the end, resulting in 400 bad request error. I would attempt to fix this myself, but I would definitely screw it up, my friend. But this is a fantastic merge!

rcalixte commented 7 months ago

The only issue is the syntax of the apiurl. It should be baseurl+stationid+format+apikey. Your syntax reversed the apikey and format is at the end, resulting in 400 bad request error.

The ordering shouldn't matter. I'm assuming you're talking about the driver for Weather Underground. You can change the order they are passed in by changing the order they are defined in the params variable. I refactored this to make it easier to not only read but to adjust parameters as needed.

I would attempt to fix this myself, but I would definitely screw it up, my friend.

I trust that you can make changes to the updated drivers. If not, I haven't made them as approachable as I thought. See if you can get a different result with the modified params. If I had a valid API key, I would check myself. Let's hope someone from the community can step up here too.

But this is a fantastic merge!

Thank you for the kind words! 🙏🏼

LinuxMint20 commented 7 months ago

It IS easy to read, very straightforward, but when I changed the order in params to in WU driver.js to `let params = {

  'stationId': encodeURIComponent(this.stationID),

  'format': 'json',

  'units': 'e',

  'apiKey': encodeURIComponent(this.apikey)

};
`

There was no change in the syntax. Course, I only reloaded the desklet. do i need to remove and then add it? perhaps restart cinnamon?

rcalixte commented 7 months ago

There was no change in the syntax. Course, I only reloaded the desklet. do i need to remove and then add it? perhaps restart cinnamon?

A restart is the brute force method but a reload of the desklet usually works. If you modified the code under ~/.local/share/cinnamon/desklets, then it should definitely be changed on a restart.

To be clear, I'm not expecting a change on the result. The ordering of the parameters in the API call shouldn't matter on the other side.

LinuxMint20 commented 7 months ago

@rcalixte Rick, I restarted cinnamon and it updates. Now I have the following error

error t=2024-02-15T18:45:20Z SERVICE_STATUS_ERROR is not defined

error t=2024-02-15T18:45:20Z co.metric is undefined

I changed the metric in the geocode back to m.

LinuxMint20 commented 7 months ago

To be clear, I'm not expecting a change on the result. The ordering of the parameters in the API call shouldn't matter on the other side.

I think we are getting close, my friend.

rcalixte commented 7 months ago

@rcalixte Rick, I restarted cinnamon and it updates. Now I have the following error

error t=2024-02-15T18:45:20Z SERVICE_STATUS_ERROR is not defined

error t=2024-02-15T18:45:20Z co.metric is undefined

I changed the metric in the geocode back to m.

This is a bug on my part. 😞

The fix is coming in a few minutes.

LinuxMint20 commented 7 months ago

To be clear, I'm not expecting a change on the result. The ordering of the parameters in the API call shouldn't matter on the other side.

I think we are getting close, my friend. I just restarted and need to get rid of an ampersand after the apikey

rcalixte commented 7 months ago

To be clear, I'm not expecting a change on the result. The ordering of the parameters in the API call shouldn't matter on the other side.

I think we are getting close, my friend. I just restarted and need to get rid of an ampersand after the apikey

That's an artifact that also shouldn't affect the result. We can strip it at the end if needed.

LinuxMint20 commented 7 months ago

That's an artifact that also shouldn't affect the result. We can strip it at the end if needed.

I'd like to try. Take some of the load off your back, however small. Does the change need to be made in wunderground driver? How would I go about it?

rcalixte commented 7 months ago

These are in #1059 and #1060. Sorry, I didn't link them.

rcalixte commented 7 months ago

I'd noticed the ampersand but none of the services seemed to process it differently if it was there so I didn't want to over-optimize. Of course, it figures that the one API that cared was one I couldn't test personally.

rcalixte commented 7 months ago

I'd like to try. Take some of the load off your back, however small. Does the change need to be made in wunderground driver? How would I go about it?

Take a look through those pull requests as they map to our conversation and then I'll leave the rest to you. 😅

The code is fresh in my mind so it's fairly easy to remember what is where and push the fix. I would love to know how it's working now.

LinuxMint20 commented 7 months ago

only error im getting now is https://api.weather.com/v3/wx/forecast/daily/5day... im looking for the apiurl for forecast in the main documentation at the links they gave me. I'll retest after I change it and let you know

rcalixte commented 7 months ago

Good luck! Feel free to open a pull request if you can get something working!

LinuxMint20 commented 7 months ago

@rcalixte Rick, Im sorry to keep pestering you with this. I know you closed it. I just have one question; what does co.metric is undefined mean? I commented out the lines for // get the main object to update the display with v3 address in it, just to test the driver, and this was the result. I looked up the term on duck and the explanations are way over my head.

rcalixte commented 7 months ago

@rcalixte Rick, Im sorry to keep pestering you with this. I know you closed it. I just have one question; what does co.metric is undefined mean? I commented out the lines for // get the main object to update the display with v3 address in it, just to test the driver, and this was the result. I looked up the term on duck and the explanations are way over my head.

It means there's a reference to that before it is defined previously or it might not exist at all in the case of the JSON response. The best thing to do is see if you can get a JSON response and then parse that after the fact. Take a look at one of the working drivers for an example, both what returns from the service and then how it's processed.

LinuxMint20 commented 7 months ago

Thanks :)

LinuxMint20 commented 7 months ago

@rcalixte Rick,

t means there's a reference to that before it is defined previously or it might not exist at all in the case of the JSON response. The best thing to do is see if you can get a JSON response and then parse that after the fact. Take a look at one of the working drivers for an example, both what returns from the service and then how it's processed.

Could it be import? My debugger in VS Code says import is not defined. Might that need to be assigned? This code is above my head. Managed to figure out the address, tho, both apiurls work now :D

This is the code.

// Weather Underground Driver

const GLib = imports.gi.GLib;

const Gettext = imports.gettext;

const UUID = 'bbcwx@oak-wood.co.uk';

const DESKLET_DIR = imports.ui.deskletManager.deskletMeta[UUID].path;

imports.searchPath.push(`${DESKLET_DIR}/drivers`);

const wxBase = imports.wxbase;
rcalixte commented 7 months ago

Could it be import? My debugger in VS Code says import is not defined. Might that need to be assigned? This code is above my head. Managed to figure out the address, tho, both apiurls work now :D

Do you have the development packages installed on your system? That's the only thing I can think of outside of maybe configuring VSCode specifically. On your system, right-click on a panel and go to Troubleshooting -> Looking Glass. That is the built-in tool that you can use to run/test code as well as debug. I would have to circle back to see if there is a way to configure VSCode with the CJS environment.

rcalixte commented 7 months ago

I want to say libglib2.0-dev is the correct package here, assuming you're using a recent version of Mint. I believe that all of the other dependencies should already be installed.

LinuxMint20 commented 7 months ago

Looking Glass has been invaluable. It was my main source of info before I downloaded VSC on Thursday, 2 days ago, when I recognized the need I had for an editor other than the bread and butter notepad clone as default in Mint. Im sorry, I forgot to mention that that was the source of issue, the Melange error. It still reads error t=2024-02-17T15:42:01Z co.metric is undefined, and I haven't the knowledge to tackle that one. I have tried, my friend. Ive spent countless hours in the last two/three days tweaking the code, addressing the apiurl issue and looking up the co.metric error online.

LinuxMint20 commented 7 months ago

I want to say libglib2.0-dev is the correct package here, assuming you're using a recent version of Mint.

21.3, Vanessa, just updated recently when I bought this computer this month

rcalixte commented 7 months ago

That error is due to it not being in the JSON response. Did you open the url for the API in a browser? I find Firefox to be the better tool here. You can search for that key value in the response as well as collapse other components.

rcalixte commented 7 months ago

21.3, Vanessa, just updated recently when I bought this computer this month

See if libgirepository1.0-dev is installed. That should handle some of the base dependencies for development.

LinuxMint20 commented 7 months ago

Okay, thank you so much :) This is the output of the geocode uri: failure " Not enough parameters for this api. language, "

and pws uri:

success false

errors  

0   

code    "EAE:NEP-0001"

message "Not enough parameters for this api.  

language,countyId,iataCode,icaoCode,postalKey,ski,zoneId,placeid,geocode,globalAirQuality,key,leaf,tide,adminDistrictCode,areaId,geocode,countryCode"

metadata    

transaction_id  "1429140092945:1801695336"

status_code 400
LinuxMint20 commented 7 months ago

I want to say libglib2.0-dev is the correct package here

Just installed it and I will test. I hope the above information helps you troubleshoot

rcalixte commented 7 months ago

Okay, thank you so much :) This is the output of the geocode uri: failure " Not enough parameters for this api. language, "

and pws uri:

success   false

errors    

0 

code  "EAE:NEP-0001"

message   "Not enough parameters for this api.  

language,countyId,iataCode,icaoCode,postalKey,ski,zoneId,placeid,geocode,globalAirQuality,key,leaf,tide,adminDistrictCode,areaId,geocode,countryCode"

metadata  

transaction_id    "1429140092945:1801695336"

status_code   400

That's... not what their documentation says is required. 😑

Let me see if I can test this better locally.