# October 2021, copyleft || Kamome and Funix || Speech-to-Derive * The Myth of Natural Language || Roodkapje, Rotterdam # Scrape images from DuckDuckGo # # With duckduckgo_images_api! from duckduckgo_images_api import search # import the library for scrape # to create delays :: for having a few seconds to check the console import time with open('../speech.txt', 'r') as speech: # let's import the text # and split it in lines, it will create an array, a list qq = speech.readlines() print(qq) # print the array! time.sleep(2) # check qq in the console! # declare the first part of the text of the html, we will fill it # in the process with loops html = ''' 📡 💻📘

Title!

NamesFunix and Kamo

''' # Elaborate each line :: process every element of the array qq # q is for "query", qq for "queries", because we will send requests to # DuckDuckGo searching the text of each line of speech.txt for q in qq: print(q) # print the q! time.sleep(2) # check current q in the console! q = q.strip() # remove "\n", which means "return to the next line" q = q.replace("\n", "") # Scrape images with search()! # q is, indeed, the query for DuckDuckGo results = search(q) r = results["results"][0]["image"] # get the http link to the image html += f""" {q} \n""" # Now let's fill the html with text and the pic html += f""" \n""" # Close the html text html += ''' ''' html = html.replace(" '", "'") with open('../2_layout/3.html', 'w') as index: # Save the file! index.write(html)