Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
""" Input file: .csv with kw1, kw2, biz name, location, ST
Output: 160 chars or less of word-replaced random combo of 1st, 2nd, 3rd sentence. Length <= 160 chars
"""
import random
import csv
firstSentence = ["Interested in KW1? ", "Looking for KW1? ", "Considering KW1? ", "Searching for KW1 in LOCATION, ST? "];
secondSentence = ["BIZNAME specializes in KW2 in the LOCATION area. ","BIZNAME is an expert in KW2 in LOCATION, ST. ","BIZNAME performs this procedure in the LOCATION, ST area. ","Explore the website BIZNAME, who performs KW2 in the LOCATION area. "];
thirdSentence = ["Click here for photos!","Click here for before and after photos!","Find more info here!","Contact us today!"];
outputFile = open('output.txt', 'w')
def replaceStrings(myList):
l = []
l.append(random.choice(firstSentence))
l.append(random.choice(secondSentence))
l.append(random.choice(thirdSentence))
s = ''.join(l)
s = s.replace("KW1", myList[0])
s = s.replace("KW2", myList[1])
s = s.replace("BIZNAME", myList[2])
s = s.replace("LOCATION", myList[3])
s = s.replace("ST", myList[4])
if len(s) < 160:
s = s + '\n\n'
print (s)
outputFile.write(s)
else:
replaceStrings(myList)
with open('inputSample.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
replaceStrings(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment