Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple country search, is this possible? #121

Open
Denon9205 opened this issue Aug 13, 2023 · 2 comments
Open

Multiple country search, is this possible? #121

Denon9205 opened this issue Aug 13, 2023 · 2 comments

Comments

@Denon9205
Copy link

googlenews_de = GoogleNews(lang='de', region='DE', encode='utf-8')
googlenews_us = GoogleNews(lang='en', region='US', encode='utf-8')
googlenews_uk = GoogleNews(lang='en', region='GB', encode='utf-8')
googlenews_ch = GoogleNews(lang='de', region='CH', encode='utf-8')
googlenews_at = GoogleNews(lang='de', region='AT', encode='utf-8')

Is a multiple search possible, if so is that correct?

I often get e.g. German links from the US or UK search and vice versa.

@HurinHu
Copy link
Member

HurinHu commented Aug 13, 2023

Google never gaurantee the accurate result

@Denon9205
Copy link
Author

I have created a workaround.

def is_valid_url_endings(url: str, country_name: str) -> bool:
valid_endings_per_region = {
"USA": [".com", ".co.uk"],
"UK": [".com", ".co.uk"],
"Deutschland": [".de", ".at", ".ch"],
"Schweiz": [".de", ".at", ".ch"],
"Oesterreich": [".de", ".at", ".ch"],
}

parsed_url = urlparse(url)
domain_parts = parsed_url.netloc.split('.')
domain_ending = '.' + domain_parts[-1]

valid_endings = valid_endings_per_region.get(country_name, [])

if domain_ending in valid_endings:
    logging.info(f"Die URL '{url}' hat die zulässige Endung '{domain_ending}' für das Land '{country_name}' und wird als gültig betrachtet.")
    return True
else:
    logging.warning(f"Die URL '{url}' hat keine der zulässigen Endungen {valid_endings} für das Land '{country_name}' und wird als ungültig betrachtet.")
    return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants