-
Notifications
You must be signed in to change notification settings - Fork 2
/
sign.py
executable file
·158 lines (140 loc) · 6.25 KB
/
sign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3 -t
"""Trevor Stone's random signature script."""
from __future__ import with_statement
import random
import os
import sys
def randline(filename, *filters):
with open(filename) as f:
seen = 0
choice = ''
for line in f:
line = line.rstrip() # always remove newline and trailing spaces
for filter in filters:
line = filter(line)
if not line:
break
if not line:
continue # because we can't continue to an outer loop
seen += 1
if random.randrange(0, seen) == 0:
choice = line
return choice
def linebreak(s, width):
s = s.rstrip()
lines = []
while len(s) > width:
attribIndex = s.rfind('--')
if attribIndex > 0 and len(s) - attribIndex <= width and attribIndex <= width:
lines.append(s[:attribIndex].rstrip())
lines.append(s[attribIndex:].strip())
s = ''
else:
i = width
while not s[i].isspace():
i -= 1
line = s[:i].rstrip()
s = s[i+1:].lstrip()
attribIndex = s.rfind('--')
if line.endswith('--'):
line = line[:len(line)-2]
s = '-- ' + s
lines.append(line)
if s:
lines.append(s.rstrip())
return lines
def justify(a, b, width): # doesn't wrap lines!
if len(a) + len(b) >= width:
return a + ' ' + b
return a + b.rjust(width - len(a))
class WordList:
"""Provides random words from a list."""
def __init__(self, items):
self.items = items
def one(self):
"""Returns one random word."""
return random.choice(self.items)
# one-word adjectives
adjective1 = WordList(('artless', 'bawdy', 'beslubbering', 'bootless', 'brazen',
'churlish', 'cockered', 'clouted', 'craven', 'currish', 'dankish',
'dissembling', 'distempered', 'droning', 'errant', 'fawning', 'fitful',
'fobbing', 'froward', 'frothy', 'gleeking', 'gnarling', 'goatish',
'gorbellied', 'greasy', 'grizzled', 'haughty', 'hideous', 'impertinent',
'infectious', 'jaded', 'jarring', 'knavish', 'lewd', 'loggerheaded',
'lumpish', 'mammering', 'mangled', 'mewling', 'paunchy', 'peevish',
'pernicious', 'prating', 'pribbling', 'puking', 'puny', 'purpled',
'quailing', 'queasy', 'rank', 'reeky', 'roguish', 'roynish', 'ruttish',
'saucy', 'sottish', 'spleeny', 'spongy', 'surly', 'tottering', 'unmuzzled',
'vacant', 'vain', 'venomed', 'villainous', 'waggish', 'wanton', 'warped',
'wayward', 'weedy', 'wenching', 'whoreson', 'yeasty'))
# hyphenated adjectives
adjective2 = WordList(('base-court', 'bat-fowling', 'beef-witted',
'beetle-headed', 'boil-brained', 'bunched-backed', 'clapper-clawed',
'clay-brained', 'common-kissing', 'crook-pated', 'dismal-dreaming',
'dizzy-eyed', 'dog-hearted', 'dread-bolted', 'earth-vexing', 'elf-skinned',
'empty-hearted', 'evil-eyed', 'eye-offending', 'fat-kidneyed', 'fen-sucked',
'flap-mouthed', 'fly-bitten', 'folly-fallen', 'fool-born', 'full-gorged',
'guts-griping', 'half-faced', 'hasty-witted', 'heavy-handed', 'hedge-born',
'hell-hated', 'horn-mad', 'idle-headed', 'ill-breeding', 'ill-composed',
'ill-nurtured', 'iron-witted', 'knotty-pated', 'lean-witted',
'lily-livered', 'mad-bread', 'milk-livered', 'motley-minded',
'muddy-mettled', 'onion-eyed', 'pale-hearted', 'paper-faced',
'pinch-spotted', 'plume-plucked', 'pottle-deep', 'pox-marked', 'raw-boned',
'reeling-ripe', 'rough-hewn', 'rude-growing', 'rug-headed', 'rump-fed',
'shag-eared', 'shard-borne', 'sheep-biting', 'shrill-gorged', 'spur-galled',
'sour-faced', 'swag-bellied', 'tardy-gaited', 'tickle-brained',
'toad-spotted', 'unchin-snouted', 'weak-hinged', 'weather-bitten',
'white-livered'))
# nouns
noun = WordList(('apple-john', 'baggage', 'barnacle', 'bladder', 'boar-pig',
'bugbear', 'bum-bailey', 'canker-blossom', 'clack-dish', 'clotpole',
'coxcomb', 'codpiece', 'crutch', 'cutpurse', 'death-token', 'dewberry',
'dogfish', 'egg-shell', 'flap-dragon', 'flax-wench', 'flirt-gill',
'foot-licker', 'fustilarian', 'giglet', 'gudgeon', 'gull-catcher',
'haggard', 'harpy', 'hedge-pig', 'hempseed', 'horn-beast', 'hugger-mugger',
'jack-a-nape', 'jolthead', 'lewdster', 'lout', 'maggot-pie', 'malignancy',
'malkin', 'malt-worm', 'mammet', 'manikin', 'measle', 'minimus', 'minnow',
'miscreant', 'moldwarp', 'mumble-news', 'nut-hook', 'pantaloon', 'pigeon-egg',
'pignut', 'puttock', 'pumpion', 'rabbit-sucker', 'rampallion', 'ratsbane',
'remnant', 'rudesby', 'ruffian', 'scantling', 'scullion', 'scut',
'skainsmate', 'snipe', 'strumpet', 'varlot', 'vassal', 'waterfly',
'whey-face', 'whipster', 'wagtail', 'younker'))
lists = (adjective1, adjective2, noun)
def curse():
return 'Thou %s!' % ' '.join([w.one() for w in lists])
def siteAndCurse(width):
websites = ('https://trevorstone.org/', 'https://flwyd.dreamwidth.org/',
'https://twitter.com/flwyd', 'https://github.com/flwyd',
'https://www.flickr.com/photos/trevorstone')
while True:
website = random.choice(websites)
s = justify(website, curse(), width)
if len(s) <= width:
return s
def commentFilter(s):
return None if len(s) == 0 or s[0] == '#' else s
def embraceAndDoit(oneliners, width):
toembrace = ('adaptation', 'art', 'beauty', 'chaos', 'change', 'choice',
'community', 'creativity', 'culture', 'curiosity', 'discovery',
'diversity', 'excitement', 'expression', 'exploration', 'existence',
'family', 'flow', 'friendship', 'growth', 'inspiration', 'joy',
'knowledge', 'laughter', 'metaphor', 'love', 'novelty', 'oddity',
'principle', 'ritual', 'science', 'self', 'singularity', 'society',
'solitude', 'spontaneity', 'surprise', 'wildness', 'wonder')
while True:
embrace = '{embrace %s}' % random.choice(toembrace)
doit = randline(oneliners, commentFilter)
s = justify(embrace, doit, width)
if len(s) <= width:
return s
if __name__ == '__main__':
width = 71
quotefiles = ['~/lib/quotes/doitoneliners.txt', '~/lib/quotes/oneliners.txt']
quotefiles = [os.path.expanduser(p) for p in quotefiles]
print('')
print('-- ')
print('=-=-=-= Trevor Stone -=- [Flwyd] -=- <tstone @ trevorstone.org> =-=-=-=')
print('Computer science, eclectic philosophy, games, wits, esoterics, odd hats')
print(siteAndCurse(width))
print(embraceAndDoit(quotefiles[0], width))
print('\n'.join(linebreak(randline(quotefiles[1], commentFilter), width)))