Last active
February 29, 2016 23:36
-
-
Save mturilin/a08b234de0f34188c576 to your computer and use it in GitHub Desktop.
Email reformatting and quoting workflow for Alfred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_next_space(text, start): | |
while start < len(text): | |
if text[start] == " ": | |
return start | |
else: | |
start += 1 | |
return start | |
def find_next_non_space(text, start): | |
while start < len(text): | |
if text[start] != " ": | |
return start | |
else: | |
start += 1 | |
return start | |
def chunks_words(text, chunk_size): | |
i = 0 | |
res_chunks = [] | |
while i < len(text): | |
i = find_next_non_space(text, i) | |
j = i + chunk_size | |
j = find_next_space(text, j) | |
if i < len(text): | |
res_chunks.append(text[i:j]) | |
i = j | |
return res_chunks | |
SIZE = 10 | |
# query = """{query}""" | |
query = """For months, as Donald Trump developed his political repertoire, he adopted an uncharacteristic reply | |
for questions about fascism and the Ku Klux Klan: silence, or something close to it. | |
He used the technique as early as last August, when his opponents, and the press, still generally regarded him as a summer amusement. On August 26th, Bloomberg Television anchor John Heilemann brought up David Duke, the former Klan Grand Wizard, who had said that Trump was "the best of the lot" in the 2016 campaign. Trump replied that he had no idea who Duke was. Heilemann asked if Trump would repudiate Duke's endorsement. "Sure,"" Trump said, "if that would make you feel better, I would certainly repudiate. I don't know anything about him." Changing tack, Heilemann pressed Trump about an article in this magazine, which described Trump's broad support among neo-Nazis, white nationalists, and other members of the far right who were drawn in by his comments about Mexicans. Trump maintained a posture of indifference. "Honestly, John, I'd have to read the story. A lot of people like me." The interview moved on to other topics.""" | |
lines1 = query.split("\n") | |
lines2 = [] | |
for line in lines1: | |
chunks = chunks_words(line, SIZE) | |
lines2 += chunks | |
lines3 = ["> " + line for line in lines2] | |
print "\n".join(lines3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment