예제 #1
0
파일: models.py 프로젝트: Drowze/skyscraper
 def get_or_fetch(self, city_name):
     """
     get or fetch a station from a city name
     if multiple stations are found, this function return the first
     """
     #try to get a place on db
     stations = None
     stations = models.get_model("skyscanner_scraper", "Station").objects.filter(name__iexact=city_name)
     if len(stations) == 0:
         #else fetch the results
         client = SkyscannerClient()
         stations = client.get_stations(city_name)
     if len(stations) > 0:
         #return the first
         return stations[0]
예제 #2
0
 def get_or_fetch(self, city_name):
     """
     get or fetch a station from a city name
     if multiple stations are found, this function return the first
     """
     #try to get a place on db
     stations = None
     stations = models.get_model(
         "skyscanner_scraper",
         "Station").objects.filter(name__iexact=city_name)
     if len(stations) == 0:
         #else fetch the results
         client = SkyscannerClient()
         stations = client.get_stations(city_name)
     if len(stations) > 0:
         #return the first
         return stations[0]