-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
36 lines (29 loc) · 853 Bytes
/
testing.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
import unirest
import json
import re
from reddit import reddit, getFrontPage
from task import Task
class haiku(Task):
def run(self):
for subs in getFrontPage():
subArray = subs.title.split()
for i in subArray:
print "i is: " + i
matchO = re.match("^((?![,.?!;:]).)*$", i)
if matchO:
url = "https://wordsapiv1.p.mashape.com/words/" + i + "/syllables"
print "url is: " + url
# These code snippets use an open-source library. http://unirest.io/python
try:
response = unirest.get(url,
headers={
"X-Mashape-Key": "MqocUSZZ8vmshdZKANtf2ay0cP9jp1JGrdcjsn0faXKxsOlkoC",
"Accept": "application/json"
}
)
print json.loads(response.raw_body["syllables"])
except:
print "something happened"
else:
print "no match!"
haiku = haiku()