Skip to content

Instantly share code, notes, and snippets.

@cwylie0
Last active September 7, 2016 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwylie0/c6f799511d4074bae9f081c087c7b014 to your computer and use it in GitHub Desktop.
Save cwylie0/c6f799511d4074bae9f081c087c7b014 to your computer and use it in GitHub Desktop.
""" 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