-2

I've tried to install a scraper that will reflect the price of airline tickets from this GitHub page: https://kcelebi.github.io/flight-analysis/

Following the authors' steps I downloaded the code and run pip install google-flight-analysis into my command prompt which didn't seem to have any issues installing everything.

I then took the Authors' code used to run the program and pasted it into Visual Studio, the code is as follows:


# Scrapes Google Flights for round-trip JFK to IST, leave July 15, 2023, return July 25, 2023.
result = Scrape("JFK", "IST", "2023-07-15", "2023-07-25")

# Obtain data + info
flights = result.data # outputs as a Pandas dataframe
origin = result.origin # "JFK"
dest = result.dest # "IST"
date_leave = result.date_leave # "2023-07-15"
date_return = result.date_return # "2023-07-25"

I then ran the code in Visual Studio to which it returns:

Traceback (most recent call last):
  File "C:\Users\jorda\AppData\Local\Temp\tempCodeRunnerFile.python", line 10, in <module>
    date_leave = result.date_leave # "2023-07-15"
                 ^^^^^^^^^^^^^^^^^
AttributeError: '_Scrape' object has no attribute 'date_leave'

I would appreciate any help further in fixing my problem. I'm almost convinced I need to entirely uninstall python and all of the additions to in and re-install because I certainly could've messed up along the way (I have no experience in Python).

What it looks like in Visual Studio

  • I don't see an image of the syntax error. Just include the syntax error as text anyway. – mkrieger1 Aug 07 '23 at 22:15
  • 1
    I don't think you're supposed to type `&` as a command anywhere. – mkrieger1 Aug 07 '23 at 22:16
  • 1
    The dollar sign is the default command line prompt of Linux/Unix systems. Don't type it as a part of your command. – Malcolm Aug 07 '23 at 22:18
  • Dollar is like a prompt that indicate that it is terminal. Just paste ```pip install google-flight-analysis``` into terminal. Also I don't know what you are trying to do in your terminal, just right click on your editor and choose run in terminal if you don't know how to use terminal on its own. – dawid.pawlowski Aug 07 '23 at 22:20
  • And I certainly don't know what led you to use an ampersand, but that definitely isn't useful either. – Malcolm Aug 07 '23 at 22:20
  • 1) Close the terminal window and the REPL 2) Your code prints no output, currently – OneCricketeer Aug 07 '23 at 22:22
  • What exactly do you do to "run it through vB Code"? – mkrieger1 Aug 07 '23 at 22:25
  • `>>>` indicates the pythyon REPL where you can type python code to run it directly. But you are typing a Powershell command. Instead you should open a Powershell Terminal in VS Code or open Powershell in Windows to type the command. – Code-Apprentice Aug 07 '23 at 22:26
  • I literally just copied and pasted what was provided on the GitHub after installing everything necessary, and click the Run Code (Play) button at the top right of the viewer to which it returns `Traceback (most recent call last): File "c:\Users\jorda\OneDrive\Desktop\from google_flight_analysis.py", line 10, in date_leave = result.date_leave # "2023-07-15" ^^^^^^^^^^^^^^^^^ AttributeError: '_Scrape' object has no attribute 'date_leave'` @mkrieger1 – JortGibbons Aug 07 '23 at 22:28
  • That looks like a whole new problem. And we still don't know *where* you pasted *what*. – mkrieger1 Aug 07 '23 at 22:29
  • @Code-Apprentice when I run this via Powershell it returns `At line:1 char:1 + from google_flight_analysis.scrape import * + ~~~~ The 'from' keyword is not supported in this version of the language. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ReservedKeywordNotAllowed` – JortGibbons Aug 07 '23 at 22:30
  • @JortGibbons Please [edit] your question to include the error so you can format it properly. That's a different problem than the one you first asked about. – Code-Apprentice Aug 07 '23 at 22:31
  • 1
    The documentation you are referring to contains (1) shell commands and (2) Python code. You are supposed to execute shell commands in a shell and Python code in a Python session or by saving it in a Python file and executing it from the shell or by pressing the "play" button. – mkrieger1 Aug 07 '23 at 22:32
  • @mkrieger1 I pasted `from google_flight_analysis.scrape import * # Scrapes Google Flights for round-trip JFK to IST, leave July 15, 2023, return July 25, 2023. result = Scrape("JFK", "IST", "2023-07-15", "2023-07-25") # Obtain data + info flights = result.data # outputs as a Pandas dataframe origin = result.origin # "JFK" dest = result.dest # "IST" date_leave = result.date_leave # "2023-07-15" date_return = result.date_return # "2023-07-25"` into the area above the terminal in Visual Studio and ran it through the terminal. – JortGibbons Aug 07 '23 at 22:32
  • @JortGibbons "When I run this via powershell..." What is "this"? Did you paste the python code directly in a powershell terminal? It doesn't work that way. You need to save the python script in a file and then run that file in Powershell with a command similar to what you originally tried in the original version of your question. The main difference is that you shouldn't include `&` in the command. I recommend you google "run python script in windows" or something similar to see some examples of how to do this. For example: https://stackoverflow.com/questions/1027714/. – Code-Apprentice Aug 07 '23 at 22:44
  • The error you are facing now seems to be a bug in the library you are trying to use. Maybe you got an outdated version of the library which doesn't match the documentation you found. – mkrieger1 Aug 07 '23 at 22:51

0 Answers0