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

I want to get datetime in Japanese news. #58

Open
taruscript opened this issue Mar 31, 2021 · 2 comments
Open

I want to get datetime in Japanese news. #58

taruscript opened this issue Mar 31, 2021 · 2 comments

Comments

@taruscript
Copy link

Currently, I did get news in Japanese, datetime is set to None.
But I did changed language to en, datetime is setted. please fix it.

from GoogleNews import GoogleNews
import datetime

dt_now = datetime.datetime.now().date()


googlenews = GoogleNews(lang="ja", encode='utf-8')
googlenews.set_time_range(start=dt_now, end=dt_now)
googlenews.get_news("ビットコイン")
results = googlenews.results()


for result in results:
    print(result["datetime"])
@HurinHu
Copy link
Member

HurinHu commented Apr 15, 2021

result['date'] is working, datetime is not always available, will check alternative solution later.

@adam-az
Copy link

adam-az commented Jun 14, 2022

I had the same problem for Dutch.
Apparently now the date is being returned in the local language?
For Dutch news, this means you need to use:

  def define_date(date):
        months = {"jan": 1, "feb": 2, "mar": 3, "apr": 4, "mei": 5, "jun": 6, "jul": 7, "aug": 8, "sep": 9, "okt": 10,
                  "nov": 11, "dec": 12}
        try:
            if "geleden" in date.lower():
                q = int(date.split()[-3])
                if re.search(r"(minuten|minuut)", date.lower()):
                    return dt.datetime.now() + relativedelta(minutes=-q)
                elif re.search(r"(uur|uren)", date.lower()):
                    return dt.datetime.now() + relativedelta(hours=-q)
                elif re.search(r"(dag|dagen)", date.lower()):
                    return dt.datetime.now() + relativedelta(days=-q)
                elif re.search(r"(week|weken)", date.lower()):
                    return dt.datetime.now() + relativedelta(days=-7 * q)
                elif re.search(r"(maand|maanden)", date.lower()):
                    return dt.datetime.now() + relativedelta(months=-q)
            elif "gisteren" in date.lower():
                return dt.datetime.now() + relativedelta(days=-1)
            else:
                for month in months.keys():
                    if month.lower() + " " in date.lower():
                        date_list = date.replace(",", "").split()[-3:]
                        return dt.datetime(day=int(date_list[1]), month=months[month], year=int(date_list[2]))
        except:
            return float("nan")

The function would need to be adapted for every language.

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

3 participants