-
Notifications
You must be signed in to change notification settings - Fork 3
/
getMaterials.py
77 lines (69 loc) · 2.28 KB
/
getMaterials.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
import requests
import json
import csv
from io import StringIO
url = 'http://watchout4snakes.com/wo4snakes/Random'
def getVerbs():
data = {'Level': 20, 'Pos': 't'}
words = []
while len(words) < 100:
r = requests.post('{0}/RandomWordPlus'.format(url), data=data)
if r.content.decode('utf-8').endswith('ing'):
words.append(r.content.decode('utf-8'))
print('got a word: %s' % r.content)
with open('json_data/verbs.json', 'w') as f:
f.write(json.dumps(words))
def getNounPhrases():
data = {
'Level1': 20,
'Pos1': 'a',
'Level2': 20,
'Pos2': 'n',
}
words = []
while len(words) < 100:
r = requests.post('{0}/RandomPhrase'.format(url), data=data)
words.append(r.content.decode('utf-8'))
print('got a word: %s' % r.content)
with open('json_data/noun_phrases.json', 'a') as f:
f.write(json.dumps(words))
def getAgencies():
agencies = []
with open('raw_data/USGOV.csv', 'r') as f:
reader = csv.reader(f)
agencies = [r[0] for r in reader]
with open('json_data/agencies.json', 'w') as f:
f.write(json.dumps(agencies))
def getOrgs():
orgs = []
with open('raw_data/NONPROFITS.csv', 'r') as f:
reader = csv.reader(f)
next(reader)
orgs = [o[1] for o in reader]
with open('json_data/orgs.json', 'w') as f:
f.write(json.dumps(orgs))
def getServices():
services = []
with open('raw_data/services.txt', 'r') as f:
reader = csv.reader(f)
services = [r[0] for r in reader]
with open('json_data/services.json', 'w') as f:
f.write(json.dumps(services))
def getResources():
resources = requests.get('https://docs.google.com/spreadsheet/pub?key=0AtbqcVh3dkAqdDZFaTlwRlBDczVGbUtJUnNwVnZ2ZVE&output=csv')
resources = StringIO(resources.content.decode('utf-8'))
reader = csv.reader(resources)
header = next(reader)
keepers = []
for row in reader:
if row[0] and row[2]:
keepers.append({'title': row[0], 'url': row[2]})
with open('json_data/resources.json', 'w') as f:
f.write(json.dumps(keepers))
if __name__ == "__main__":
# getVerbs()
# getNounPhrases()
# getAgencies()
# getOrgs()
# getResources()
getServices()