I need to select only a certain number of (random) keywords from the list at a time and not make an API call with all the keys as is the case now. How can I proceed?
# Search keywords definition
keywords = ["Televisori", "Notebook", "Tablet", "Apple", "Samsung", "Smartwatch", "Auricolari Bluetooth", "Fotocamera",
"Videocamera"]
# run bot function
def run_bot(bot, keywords):
# shuffling keywords list
random.shuffle(keywords)
# start loop
while True:
try:
items_full = []
# iterate over keywords
for el in keywords:
# iterate over pages
for i in range(1, 10):
items = search_items(el, CATEGORY, item_page=i)
# api time limit for another http request is 1 second
time.sleep(1)
items_full.append(items)
# concatenate all results
items_full = list(chain(*items_full))
Aucun commentaire:
Enregistrer un commentaire