-
Notifications
You must be signed in to change notification settings - Fork 0
/
esvtoleet.py
executable file
·69 lines (57 loc) · 1.99 KB
/
esvtoleet.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
#!/usr/bin/env python
import requests
import sys
import json
import urllib2
import urllib
class LeetSpeak():
def __init__(self):
self.x = '1337'
def toLeet(self, text):
leet = (
(('are', 'Are'), 'r'),
(('ate', 'Ate'), '8'),
(('that', 'That'), 'tht'),
(('you', 'You'), 'j00'),
(('o', 'O'), '0'),
(('i', 'I'), '1'),
(('e', 'E'), '3'),
(('s', 'S'), '5'),
(('a', 'A'), '4'),
(('t', 'T'), '7'),
)
for symbols, replaceStr in leet:
for symbol in symbols:
text = text.replace(symbol, replaceStr)
return text
class ESVAPIv3:
def __init__(self):
options = ['include-footnotes=false',
'include-short-copyright=false',
'include-passage-horizontal-lines=false',
'include-heading-horizontal-lines=false',
'include-headings=false']
self.options = '&'.join(options)
def doPassageQuery(self, passage):
token = "b8c82a38daaea9fd91c7dcd31b2433f0e4d95172"
self.url = "https://api.esv.org/v3/passage/html/"
if passage is not None:
passage = passage.split()
passage = '+'.join(passage)
json_url = self.url + '?q=%s&%s' % (passage, self.options)
data = requests.get(json_url, headers={'User-Agent': 'Mozilla/5.0', 'Authorization': 'Token ' + token})
return data.json()['passages'][0]
if __name__ == '__main__':
bible = ESVAPIv3()
leet = LeetSpeak()
try:
print leet.toLeet(bible.doPassageQuery(sys.argv[1]))
exit(1)
except IndexError:
text = ''
print "The ESV Bible passage leetspeak translator."
print "Enter a passage to translate to leetspeak (ex. Ecc 3:11) or 'quit' to end."
passage = raw_input('Enter passage: ')
while passage != 'quit':
print leet.toLeet(bible.doPassageQuery(passage))
passage = raw_input('Enter passage: ')