Skip to content

Instantly share code, notes, and snippets.

@angelabauer
Created October 21, 2020 10:29
Show Gist options
  • Save angelabauer/99301f807578ad8b6f54e8fb8ec7162b to your computer and use it in GitHub Desktop.
Save angelabauer/99301f807578ad8b6f54e8fb8ec7162b to your computer and use it in GitHub Desktop.
from pprint import pprint
import requests
SHEETY_PRICES_ENDPOINT = YOUR SHEETY PRICES ENDPOINT URL
class DataManager:
def __init__(self):
self.destination_data = {}
def get_destination_data(self):
# 2. Use the Sheety API to GET all the data in that sheet and print it out.
response = requests.get(url=SHEETY_PRICES_ENDPOINT)
data = response.json()
self.destination_data = data["prices"]
# 3. Try importing pretty print and printing the data out again using pprint().
# pprint(data)
return self.destination_data
# 6. In the DataManager Class make a PUT request and use the row id  from sheet_data
# to update the Google Sheet with the IATA codes. (Do this using code).
def update_destination_codes(self):
for city in self.destination_data:
new_data = {
"price": {
"iataCode": city["iataCode"]
}
}
response = requests.put(
url=f"{SHEETY_PRICES_ENDPOINT}/{city['id']}",
json=new_data
)
print(response.text)
import requests
TEQUILA_ENDPOINT = "https://tequila-api.kiwi.com"
TEQUILA_API_KEY = YOUR FLIGHT SEARCH API KEY
class FlightSearch:
def get_destination_code(self, city_name):
location_endpoint = f"{TEQUILA_ENDPOINT}/locations/query"
headers = {"apikey": TEQUILA_API_KEY}
query = {"term": city_name, "location_types": "city"}
response = requests.get(url=location_endpoint, headers=headers, params=query)
results = response.json()["locations"]
code = results[0]["code"]
return code
# 4. Pass the data back to the main.py file, so that you can print the data from main.py
from data_manager import DataManager
data_manager = DataManager()
sheet_data = data_manager.get_destination_data()
# print(sheet_data)
# 5. In main.py check if sheet_data contains any values for the "iataCode" key.
# If not, then the IATA Codes column is empty in the Google Sheet.
# In this case, pass each city name in sheet_data one-by-one
# to the FlightSearch class to get the corresponding IATA code
# for that city using the Flight Search API.
# You should use the code you get back to update the sheet_data dictionary.
if sheet_data[0]["iataCode"] == "":
from flight_search import FlightSearch
flight_search = FlightSearch()
for row in sheet_data:
row["iataCode"] = flight_search.get_destination_code(row["city"])
print(sheet_data)
data_manager.destination_data = sheet_data
data_manager.update_destination_codes()
@YaldaKarimii
Copy link

It's very hard to find support here, youtube's comment section always has all the answers sadly here it's no helping at all. the code is not working for updating the sheety page(iata codes). i used the same code of Angela.

yes i also have the same issue

It's very hard to find support here, youtube's comment section always has all the answers sadly here it's no helping at all. the code is not working for updating the sheety page(iata codes). i used the same code of Angela.

i find the solution delete all value in (iata code) then run your code it will work

@kriswen
Copy link

kriswen commented Apr 6, 2024

it's because in angela's code main.py line 13, it's only checking if the first row of iata is empty, then it will run through the sheet_data, like this if sheet_data[0]["iataCode"] == "":

below is how i did it in main.py instead, it'll loop through every row of iata in sheet_data, and update if it's empty:

for row in sheet_data:
    if row["iataCode"] == "":
        row["iataCode"] = fs.get_dest_code(row["city"])
        dm.update_row_data(row["id"])

@chiragkaushikofficial
Copy link

It's very hard to find support here, youtube's comment section always has all the answers sadly here it's no helping at all. the code is not working for updating the sheety page(iata codes). i used the same code of Angela.

"Share your github repo or ss here"

@by-Soulhunt
Copy link

Hi there. I have a problem. I сan't register on tequila.kiwi.com. Has anyone encountered this problem?
tequila kiwi com

@mohammodali
Copy link

Hi there. I have a problem. I сan't register on tequila.kiwi.com. Has anyone encountered this problem? tequila kiwi com
same here

@EugeneAckerman101
Copy link

Seems Tequila / Kiwi does not do charity flight info anymore.

Trying to build the solution with Amadeus for Developers, not feeling very lucky or successful though :-)

I see many have tried this route and posted solutions but when I copy them down to test them before I commit they all kick up errors that i cant understand, let alone solve. Anyway, good luck to those that try to wander here

https://developers.amadeus.com/

@K-Musty
Copy link

K-Musty commented Nov 1, 2024

Hi there. I have a problem. I сan't register on tequila.kiwi.com. Has anyone encountered this problem? tequila kiwi com
same here

Try using aviationstack instead

@K-Musty
Copy link

K-Musty commented Nov 1, 2024

If you try using Tequila and it doesn't give you access, try aviationstack and finally input the IATA codes directly to sheet and continue the task. i spent a whole day searching for APIs with no success in sight. Patience is Key

@ShmRhm
Copy link

ShmRhm commented Jan 24, 2025

image
I used "avaiationstack" instead of "Tequila". Here is the code for flight_search class.

@SadSack963
Copy link

@ShmRhm
I know Angela looked at Aviationstack when Tequila became unviable. I think the limited free requests (100 per month) put her off. Did you find that this was an issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment