def run(self): '''Defines the threads activity. Makes a row in the PlanetModel table with the corresponding data pulled from a request to the Star Wars API. ''' id = self.__url.split("/") data = requests.get(self.__url) obj = data.json() films_arr = obj.get("films") residents_arr = obj.get("residents") PlanetModel.create(id=id[-1], name=obj.get("name").encode("utf-8"), climate=obj.get("climate")) planet = PlanetModel.get(PlanetModel.id == id[-1]) for film in films_arr: this_id = film.split("/") this_id = this_id[-2] planet.films.add(FilmThread.ordered_arr[int(this_id) - 1]) for resident in residents_arr: this_id = resident.split("/") this_id = this_id[-2] planet_res = PeopleModel.select().where(PeopleModel.id == this_id) planet.residents.add(planet_res)
def run(self): """Defines the threads activity. Makes a row in the PeopleModel table with the corresponding data pulled from a request to the Star Wars API. """ id = self.__url.split("/") data = requests.get(self.__url) obj = data.json() films_arr = obj.get("films") PeopleModel.create(id=id[-1], name=obj.get("name").encode("utf-8")) character = PeopleModel.get(PeopleModel.id == id[-1]) for film in films_arr: this_id = film.split("/") this_id = this_id[-2] character.films.add(FilmThread.ordered_arr[int(this_id) - 1])
def run(self): '''Defines the threads activity. Makes a row in the PeopleModel table with the corresponding data pulled from a request to the Star Wars API. ''' id = self.__url.split("/") data = requests.get(self.__url) obj = data.json() films_arr = obj.get("films") PeopleModel.create(id=id[-1], name=obj.get("name").encode("utf-8")) character = PeopleModel.get(PeopleModel.id == id[-1]) for film in films_arr: this_id = film.split("/") this_id = this_id[-2] character.films.add(FilmThread.ordered_arr[int(this_id) - 1])
def run(self): """Defines the threads activity. Makes a row in the PlanetModel table with the corresponding data pulled from a request to the Star Wars API. """ id = self.__url.split("/") data = requests.get(self.__url) obj = data.json() films_arr = obj.get("films") residents_arr = obj.get("residents") PlanetModel.create(id=id[-1], name=obj.get("name").encode("utf-8"), climate=obj.get("climate")) planet = PlanetModel.get(PlanetModel.id == id[-1]) for film in films_arr: this_id = film.split("/") this_id = this_id[-2] planet.films.add(FilmThread.ordered_arr[int(this_id) - 1]) for resident in residents_arr: this_id = resident.split("/") this_id = this_id[-2] planet_res = PeopleModel.select().where(PeopleModel.id == this_id) planet.residents.add(planet_res)