nextcloud / weather

⛅️ Weather app for Nextcloud
GNU Affero General Public License v3.0
47 stars 27 forks source link

Fix -- Error with Nextcloud 22.1.0 even with API key set #97

Open Joecowboy opened 3 years ago

Joecowboy commented 3 years ago

I apologize for not making a pull request for this.

I am currently running: Nextcloud v22.1.0 PHP version v8.0.8 Ubuntu v21.10

I kept kept getting the "Fatal error" after trying to add a City. Looked at the Console window on web browser and kept getting a 500 error with angular.min.js. So I updated to the latest build from Google. Then noticed after that in Nextcloud log PHP error with array in error check for if the json_decode array 502 check.

I made it to where you can now add the City ID in the City Name field to add your city. So now works with either City, State or the City ID.

You can get the City ID by doing a search here: https://openweathermap.org/city/

Example: New York, New York When you search it will pop up two choices to choose from: New York City, US New York, US

So if you choose the second one the url will return: https://openweathermap.org/city/5128638

Take the 5128638 and past it into the Nextcloud Weather - Add City field textbox and click the ADD button. It will pull up the City by the City ID and will list the ID above the Add a city... However, when you refresh it will display the City name that you have chosen.

So, update the CityController.php by copying it into the following directory or wherever you have your Nextcloud installed. /var/www/nextcloud/apps/weather/lib/Controller/CityController.php

You might not need the WeatherController.php update. However, I didn't test it without the update to it. Because, I updated CityController.php to pull the City Name and Country from the json info to add this name to the database as an after thought to display the proper name instead of the City ID. /var/www/nextcloud/apps/weather/lib/Controller/WeatherController.php

Same goes for the angular.min.js copy it to the following directory or to wherever you installed Nextcloud. /var/www/nextcloud/apps/weather/js/angular.min.js

These fixes should not affect it from working on older builds of Nextcloud that this app supports.

Fix_For_Latest_Nextcloud_Build.zip

Joecowboy commented 3 years ago

I apologize once again I do not have it setup to push a Pull Request.

You can now search on: ZIP Code,Country Code Latitude,Longitude City ID City,State,Country Code

So, update the following files by copying all of them into the following directories or wherever you have your Nextcloud installed. /var/www/nextcloud/apps/weather/lib/Controller/CityController.php /var/www/nextcloud/apps/weather/lib/Controller/WeatherController.php /var/www/nextcloud/apps/weather/js/angular.min.js

Same as before it will initially show you your search results above the "Add a city...". You can put in the text box search field the following examples:

Example for New York = ZIP Code,Country Code: 10001,US

Example for New York = City ID: 5128638

Example for New York = Latitude,Longitude: 40.7484,-73.9967

Example for regular search New York City: New York City, New York, US

If you search on {City ID}, {Latitude,Longitude} or {ZIP Code,Country Code} when you refresh it will display City Name, Country Code, City ID. Added the City ID to the end to make sure it grabbed the correct city to display.

Fix_For_Latest_Nextcloud_Build.zip