-
Notifications
You must be signed in to change notification settings - Fork 1
/
plwbbot.py
109 lines (79 loc) · 2.85 KB
/
plwbbot.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
# -*- coding: utf-8 -*-
###############################################################################
"""Create mock tips/stories for the Prolife Whistle Blower anonymous tip line.
https://prolifewhistleblower.com/anonymous-form/
Inspired by (ported from) SKEPDIMI/plwbbot
https://github.com/SKEPDIMI/plwbbot
"""
# Standard library imports
import json
import random
import string
###############################################################################
def typo(phrase, rate = 0.02):
new_phrase = []
words = phrase.split(' ')
for word in words:
outcome = random.random()
if outcome <= rate and len(word) > 3:
ix = random.choice(range(len(word)))
new_word = ''.join([
word[w] if w != ix else random.choice(string.ascii_lowercase)
for w in range(len(word))
])
new_phrase.append(new_word)
else:
new_phrase.append(word)
new_phrase = ' '.join([w for w in new_phrase])
if random.random() < 0.5:
new_phrase += "."
return new_phrase
def get_time():
'''Return a random "3 weeks" like time frame.'''
number = random.randint(2, 5)
units = random.choice(["weeks", "months", "days"])
return f"{number} {units}"
# ------------------------------------------------------------------------------------ #
# Load data arrays (for random picking)
first_names = json.load(open('data/firstNames.json'))
social_media = json.load(open('data/socialMedia.json'))
clinics = json.load(open('data/clinics.json'))
zip_codes = json.load(open('data/zip_codes.json'))
told_variants = json.load(open('data/toldVariants.json'))
photo_variants = json.load(open('data/photoVariants.json'))
state_variants = json.load(open('data/stateVariants.json'))
stories = json.load(open('answer_generator/stories.json'))
evidence = json.load(open('answer_generator/evidence.json'))
data = {
"name" : random.choice(first_names),
"social" : random.choice(social_media),
"told" : random.choice(told_variants),
"photos" : random.choice(photo_variants),
"clinic" : random.choice(clinics[0]) + random.choice(clinics[1]),
"state" : random.choice(state_variants),
"location" : random.choice(zip_codes),
"time" : get_time(),
}
# ------------------------------------------------------------------------------------ #
print("Story:")
print(typo(random.choice(stories).format(**data)))
print("")
print("Evidence:")
print(typo(random.choice(evidence).format(**data)))
print("")
print("Clinic:")
print(data["clinic"])
print("")
print("City:")
print(data["location"]['city'])
print("")
print("State:")
print(data["state"])
print("")
print("Zip:")
print(data["location"]['zip'])
print("")
print("County:")
print(data["location"]['county'])
print("")
###############################################################################