victrme / Bonjourr

Minimalist & lightweight startpage inspired by iOS
https://bonjourr.fr
GNU General Public License v3.0
880 stars 104 forks source link

Enhancement: Dynamically Change URL in Weather Module Based on User's Preferred Language #320

Open zfyzmh opened 5 months ago

zfyzmh commented 5 months ago

The click-through on the weather module should switch the URL link based on the preferred language instead of always being 'en-us' 'https://www.msn.com/en-us/weather/forecast/'.

天气模块的点击跳转根据首选语言来进行切换url链接而不是永远的 en-us 'https://www.msn.com/en-us/weather/forecast/'

victrme commented 5 months ago

Hello @zfyzmh !

This was originally planned, but because their URLs path names are translated, this has to be done manually for every language:

This is annoying but doable. I don't know when this will be added though !

GhostScript0r commented 2 months ago

Hello @zfyzmh !

This was originally planned, but because their URLs path names are translated, this has to be done manually for every language:

This is annoying but doable. I don't know when this will be added though !

One possible way to do it is using a web search engine (like DuckDuckGo) to search for the URLs in for each language.

Searching for "MSN Weather site:msn.com/fr-fr" in DuckDuckGo and the the first result will be MSN weather in French language. Grab its URL and trim the URL after the 4th level (after the word "forecast").

With a list of all MSN locales, it's possible to create a JSON dictionary connecting locales and URLs with duckduckgo_search module in Python. We don't need to search for all languages, since only languages in Latin script get their URL path name translated.

victrme commented 2 months ago

I agree @GhostScript0r, that would work. It might be faster to do it manually however 😅

If you want to do that script and post your result here, that would be super helpful !

GhostScript0r commented 2 months ago

Another way will be just letting the end user customize the link.

victrme commented 2 months ago

We can already do that by selecting "Custom provider" !

GhostScript0r commented 2 months ago

I agree @GhostScript0r, that would work. It might be faster to do it manually however 😅

If you want to do that script and post your result here, that would be super helpful !

Yeah. DuckDuckGo search didn't return too many useful URLs. But at least some major languages are included.

I cannot add the result JSON file to the repo. So I'll post the result here:

{
  "ar-AE": "https://www.msn.com/ar-ae/weather",
  "bn-IN": "https://www.msn.com/bn-in/weather",
  "cs-CZ": "https://www.msn.com/cs-cz/pocasi",
  "da-DK": "https://www.msn.com/da-dk/vejr",
  "de-DE": "https://www.msn.com/de-de/wetter",
  "el-GR": "https://www.msn.com/el-gr/weather",
  "en-AE": "https://www.msn.com/en-ae/weather",
  "es-ES": "https://www.msn.com/es-es/eltiempo",
  "fi-FI": "https://www.msn.com/fi-fi/saa",
  "fr-FR": "https://www.msn.com/fr-fr/meteo",
  "he-IL": "https://www.msn.com/he-il/weather",
  "hi-IN": "https://www.msn.com/hi-in/weather",
  "hu-HU": "https://www.msn.com/hu-hu/idojaras",
  "id-ID": "https://www.msn.com/id-id/cuaca",
  "it-IT": "https://www.msn.com/it-it/meteo",
  "ja-JP": "https://www.msn.com/ja-jp/weather",
  "ko-KR": "https://www.msn.com/ko-kr/weather",
  "mr-IN": "https://www.msn.com/mr-in/weather",
  "nb-NO": "https://www.msn.com/nb-no/weather",
  "nl-NL": "https://www.msn.com/nl-nl/weer",
  "pl-PL": "https://www.msn.com/pl-pl/pogoda",
  "pt-PT": "https://www.msn.com/pt-pt/meteorologia",
  "sv-SE": "https://www.msn.com/sv-se/vader",
  "te-IN": "https://www.msn.com/te-in/weather",
  "th-TH": "https://www.msn.com/th-th/weather",
  "tr-TR": "https://www.msn.com/tr-tr/havadurumu",
  "vi-VN": "https://www.msn.com/vi-vn/weather"
}

I would suggest to first look for the links with locale settings. If only the first part of locale (language) match, the URL can already be used. If the locale is not in the list, try "https://www.msn.com/[LOCALE]/weather" since the URL for non-Latin languages is always "weather". If it returns "page not found" error, fallback to en-US website.

I would like to share the Jupyter Notebook I've written. May I add a folder to the repo?

victrme commented 2 months ago

There is no need to add any code here 😅 This issue could be manually resolved in about 20 minutes, and once all the URLs are localized, there is nothing more to do !

If you want to share your code you can link a repo or gist, but let's not over-engineer this issue !

Essentially we want the localization for these providers & languages:

const msn = {
  en: 'https://www.msn.com/en-xl/weather',
  fr: 'https://www.msn.com/en-xl/weather',
  de: 'https://www.msn.com/en-xl/weather',
  it: 'https://www.msn.com/en-xl/weather',
  es_ES: 'https://www.msn.com/en-xl/weather',
  pt_BR: 'https://www.msn.com/en-xl/weather',
  pt_PT: 'https://www.msn.com/en-xl/weather',
  nl: 'https://www.msn.com/en-xl/weather',
  da: 'https://www.msn.com/en-xl/weather',
  sv: 'https://www.msn.com/en-xl/weather',
  nb: 'https://www.msn.com/en-xl/weather',
  fi: 'https://www.msn.com/en-xl/weather',
  pl: 'https://www.msn.com/en-xl/weather',
  cz: 'https://www.msn.com/en-xl/weather',
  sk: 'https://www.msn.com/en-xl/weather',
  hu: 'https://www.msn.com/en-xl/weather',
  ro: 'https://www.msn.com/en-xl/weather',
  gr: 'https://www.msn.com/en-xl/weather',
  sr: 'https://www.msn.com/en-xl/weather',
  sr_YU: 'https://www.msn.com/en-xl/weather',
  uk: 'https://www.msn.com/en-xl/weather',
  ru: 'https://www.msn.com/en-xl/weather',
  tr: 'https://www.msn.com/en-xl/weather',
  ar: 'https://www.msn.com/en-xl/weather',
  fa: 'https://www.msn.com/en-xl/weather',
  zh_CN: 'https://www.msn.com/en-xl/weather',
  zh_HK: 'https://www.msn.com/en-xl/weather',
  jp: 'https://www.msn.com/en-xl/weather',
  id: 'https://www.msn.com/en-xl/weather',
  vi: 'https://www.msn.com/en-xl/weather',
}

const accuweather = {
  en: 'https://www.accuweather.com/',
  fr: 'https://www.accuweather.com/',
  de: 'https://www.accuweather.com/',
  it: 'https://www.accuweather.com/',
  es_ES: 'https://www.accuweather.com/',
  pt_BR: 'https://www.accuweather.com/',
  pt_PT: 'https://www.accuweather.com/',
  nl: 'https://www.accuweather.com/',
  da: 'https://www.accuweather.com/',
  sv: 'https://www.accuweather.com/',
  nb: 'https://www.accuweather.com/',
  fi: 'https://www.accuweather.com/',
  pl: 'https://www.accuweather.com/',
  cz: 'https://www.accuweather.com/',
  sk: 'https://www.accuweather.com/',
  hu: 'https://www.accuweather.com/',
  ro: 'https://www.accuweather.com/',
  gr: 'https://www.accuweather.com/',
  sr: 'https://www.accuweather.com/',
  sr_YU: 'https://www.accuweather.com/',
  uk: 'https://www.accuweather.com/',
  ru: 'https://www.accuweather.com/',
  tr: 'https://www.accuweather.com/',
  ar: 'https://www.accuweather.com/',
  fa: 'https://www.accuweather.com/',
  zh_CN: 'https://www.accuweather.com/',
  zh_HK: 'https://www.accuweather.com/',
  jp: 'https://www.accuweather.com/',
  id: 'https://www.accuweather.com/',
  vi: 'https://www.accuweather.com/',
}