Closed KevorkSulahian closed 2 years ago
For those who get similar problem. parse_validate has a problem make sure to comment it out, it's a quick but not optimal solve
I confirm the issue is still present
@bottaluscio I copied the script and commented out parse_validate part :) hope it works for you too
Thanks I was able to fix the method by re-implementing it without the date parsing check :)
Thanks @KevorkSulahian, that works for me!
This was my solution,
At the beginning, in the file ../pygooglenews/init.py, replace the line : from dateparser import parse as parse_date
with
from datetime import datetime
and add:
def parse_date(date_string): return datetime.strptime(date_string, '%Y-%m-%d')
I have this very simple code
gn = GoogleNews()
start = datetime.date(2018,3,1)
end = datetime.date(2019,3,1)
print(start)
gn.search(query="car", from=start.strftime('%Y-%m-%d'), to=end.strftime('%Y-%m-%d'))
but it's giving me the error of `
AttributeError Traceback (most recent call last) /opt/anaconda3/lib/python3.8/site-packages/pygooglenews/init.py in __from_to_helper(self, validate) 89 try: ---> 90 validate = parse_date(validate).strftime('%Y-%m-%d') 91 return str(validate)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/conf.py in wrapper(*args, *kwargs) 84 ---> 85 return f(args, **kwargs) 86 return wrapper
/opt/anaconda3/lib/python3.8/site-packages/dateparser/init.py in parse(date_string, date_formats, languages, locales, region, settings) 52 ---> 53 data = parser.get_date_data(date_string, date_formats) 54
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in get_date_data(self, date_string, date_formats) 416 for locale in self._get_applicable_locales(date_string): --> 417 parsed_date = _DateLocaleParser.parse( 418 locale, date_string, date_formats, settings=self._settings)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in parse(cls, locale, date_string, date_formats, settings) 193 instance = cls(locale, date_string, date_formats, settings) --> 194 return instance._parse() 195
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in _parse(self) 197 for parser_name in self._settings.PARSERS: --> 198 date_obj = self._parsers[parser_name]() 199 if self._is_valid_date_obj(date_obj):
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in _try_parser(self) 221 self._settings.DATE_ORDER = self.locale.info.get('date_order', _order) --> 222 date_obj, period = date_parser.parse( 223 self._get_translated_date(), settings=self._settings)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/conf.py in wrapper(*args, *kwargs) 84 ---> 85 return f(args, **kwargs) 86 return wrapper
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date_parser.py in parse(self, date_string, settings) 36 stz = get_localzone() ---> 37 date_obj = stz.localize(date_obj) 38 else:
AttributeError: 'backports.zoneinfo.ZoneInfo' object has no attribute 'localize'
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)