Bots

Whigham Rachel Covington
Data Mining the City
3 min readNov 28, 2017

The automated version of mad libs.

import json
import subprocess
import textwrap

def setup():
global sentence, hexColor, nounIcon, fabrics, socialnetworkingwebsiteData
size(400,500)

with open('passages.json') as file:
passageData = json.load(file)
passages = passageData["passages"]
randomNumPassage = int(random(0, len(passages)))
passage = passages[randomNumPassage]

with open('social_networking_websites.json') as file:
socialNetworkingWebsiteData = json.load(file)
socialNetworkingWebsites = socialNetworkingWebsiteData["socialNetworkingWebsites"]
randomNumSocialnetworkingwebsite = int(random(0, len(socialNetworkingWebsites)))
socialnetworkingwebsite = socialNetworkingWebsites[randomNumSocialnetworkingwebsite]

with open('fabrics.json') as file:
fabricData = json.load(file)
fabrics = fabricData["fabrics"]
randomNumFabric = int(random(0, len(fabrics)))
fabric = fabrics[randomNumFabric]

with open('crayola.json') as file:
crayolaData = json.load(file)
numColors = len(crayolaData["colors"])
randomColor = int(random(0, numColors))
hexColor = crayolaData["colors"][randomColor]["hex"]
crayola = crayolaData["colors"][randomColor]["color"]

with open('roomsandicons.json') as file:
roomsData = json.load(file)
roomsDict = roomsData["rooms"]
roomKeys = roomsDict.keys()
roomIndex = int(random(0, len(roomKeys)))
room = roomKeys[roomIndex]
roomUrlId = roomsDict[room]
url = 'https://d30y9cdsu7xlg0.cloudfront.net/png/'"%s"'-84.png' % roomUrlId
nounIcon = loadImage(url)

sentence = \
" Cities are made of " + passage + "s. Without " + passage + "s, we would not be able to move through cities. The physical structure of cities is important however, the way industries capitalize on available space differentiates smaller scale cities and global cities. Pop-ups are trending, dominanating " + socialnetworkingwebsite + " posts, depicting " + str(crayola) + " " + room + "s, accented with " + fabric + " lined walls."


def draw():
hexColorS = hexColor.lstrip('#')
backgroundColor = tuple(int(hexColorS[i:i+2], 16) for i in (0, 2 ,4))

background(*backgroundColor)
noFill()
noStroke()
rect(0, 0, 400, 400)

fill(0)
textSize(10)
textAlign(CENTER, CENTER)
text(sentence, 100, 200, (width/2), height/2)
image(nounIcon, 150, 100)

print(textwrap.fill(sentence, width=50))
#for sound
if frameCount == 2:
result = subprocess.check_output(['say', '"%s"' % sentence])

--

--