celebi-pkg / flight-analysis

Python package to scrape flight data from Google Flights and analyzes prices. Can determine optimal flight from date, place, and price
https://kcelebi.github.io/flight-analysis/
MIT License
127 stars 38 forks source link

ValueError time data does not match format #29

Open Kumaezenjae opened 2 months ago

Kumaezenjae commented 2 months ago

Observed bug and provided quick-fix here:

In file: ...\Python\Python312\Lib\site-packages\google_flight_analysis\flight.py

Change Line 116 from: self._times += [datetime.strptime(self._date + " " + arg, date_format) + delta] To instead be: self._times += [datetime.strptime(self._date + " " + arg.replace(' AM','AM').replace(' PM','PM'), date_format) + delta]


Traceback (most recent call last): File "", line 1, in File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\scrape.py", line 39, in ScrapeObjects debug = [obj._scrape_data(driver) for obj in tqdm(objs, desc="Scraping Objects")] ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\scrape.py", line 377, in _scrape_data results = [self._get_results(url, self._date[i], driver) for i, url in enumerate(self._url)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\scrape.py", line 405, in _get_results flights = _Scrape._clean_results(results, date) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\scrape.py", line 424, in _clean_results flights = [Flight(date, res3[matches[i]:matches[i+1]]) for i in range(len(matches)-1)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\flight.py", line 29, in init self._parse_args(*args) File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\flight.py", line 157, in _parse_args self._classify_arg(arg) File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib\site-packages\google_flight_analysis\flight.py", line 116, in _classify_arg self._times += [datetime.strptime(self._date.replace(' AM','AM').replace(' PM','PM') + " " + arg, date_format) + delta] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib_strptime.py", line 554, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myuser\AppData\Local\Programs\Python\Python312\Lib_strptime.py", line 333, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '2024-07-23 5:10 AM' does not match format '%Y-%m-%d %I:%M%p'