I am trying to create a list with the values I receive from dates, this works perfectly with dt_3
but I have to repeat the process for dt_1
, dt_7
, dt_31
. How can I simplify this process of generating the list and then passing it to start_urls
?.
plantilla = ("https://www.rentalcars.com/SearchResults.do?country=Argentina&doYear={año_devolucion}&doFiltering=true"
"&fromLocChoose=true&filterTo=49&dropLocationName={localidad}&ftsType=C&ftsLocationSearch={codigoLocalidad}"
"&dropFtsSearch=L&doDay={dia_devolucion}&searchType=allareasgeosearch&filterFrom=0&puMonth={mes_solicitud}&dropFtsInput={localidad}&dropCountry=Argentina"
"&puDay={dia_solicitud}&dropFtsLocationSearch={codigoLocalidad}&puHour=10&dropFtsEntry=22776&enabler=&distance=10"
"&ftsEntry=22776&city={localidad}&driverage=on&filterName=CarCategorisationSupplierFilter&dropCity={localidad}"
"&dropFtsType=C&ftsAutocomplete={localidad}+Argentina&driversAge=30&dropFtsAutocomplete={localidad}+Argentina"
"&dropFtsLocationName={localidad}&dropCountryCode=&doMinute=0&countryCode=&puYear={año_solicitud}&locationName=&puMinute=0&ftsInput={localidad}"
"&coordinates={cordenadas}&dropLocation={codigoLocalidad}&doHour=10&dropCoordinates={cordenadas}"
"&ftsLocationName={localidad}&ftsSearch=L&location={codigoLocalidad}&doMonth={mes_devolucion}&reducedCategory=medium&filterAdditionalInfo=&advSearch=&exSuppliers=&ordering=price")
casos = [{"localidad":"Salta",
"codigoLocalidad": "161",
"cordenadas":"-24.7833%2C-65.4167"},
{"localidad":"Mendoza",
"codigoLocalidad": "106",
"cordenadas":"-32.889%2c-68.843"},
{"localidad":"San+Carlos+de+Bariloche",
"codigoLocalidad": "-1",
"cordenadas":"-41.1335%2C-71.3102"},
{"localidad":"Tucum%C3%A1n",
"codigoLocalidad": "-1",
"cordenadas":"-26.5917%2C-65.5833"},
{"localidad":"Neuqu%C3%A9n",
"codigoLocalidad": "111",
"cordenadas":"-38.95%2C-68.0667"},
{"localidad":"Buenos+Aires",
"codigoLocalidad": "51",
"cordenadas":"-34.6038%2C-58.3816"},
{"localidad":"C%C3%B3rdoba",
"codigoLocalidad": "61",
"cordenadas":"-31.4166%2C-64.1837"}]
dias_Semana = date.today() + timedelta(7)
dt_1 = dias_Semana + timedelta(1)
dt_3 = dias_Semana + timedelta(3)
dt_7 = dias_Semana + timedelta(7)
dt_31 = dias_Semana + timedelta(31)
start_urls = []
for datos in casos:
datos.update({"año_devolucion": dt_3.year,"dia_devolucion": dt_3.day,"mes_solicitud":dias_Semana.month ,"dia_solicitud": dias_Semana.day,"año_solicitud":dias_Semana.year,"mes_devolucion":dt_3.month})
start_urls.append(plantilla.format(**datos))
You need to build a list and then iterate through the elements of it:
fecha
is the individual element of each iteration and you use it like any variable. Eventually it might be useful for the final list to contain the date.In this case the list
start_urls
will contain tuples, where the first element will be thefecha
and the second the urls.