-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathinstitutions.py
41 lines (31 loc) · 1020 Bytes
/
institutions.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
from elasticsearch import Elasticsearch
from elasticsearch_dsl import DocType, String, Boolean, Integer
from elasticsearch_dsl.connections import connections
from scrapi.settings import ELASTIC_URI, ELASTIC_INST_INDEX, ELASTIC_TIMEOUT
connections.create_connection(hosts=[ELASTIC_URI])
def setup():
Institution.init()
def remove():
es = Elasticsearch(ELASTIC_URI, request_timeout=ELASTIC_TIMEOUT)
es.indices.delete(ELASTIC_INST_INDEX)
class Institution(DocType):
name = String()
established = String()
location = {
'street_address': String(),
'city': String(),
'state': String(),
'country': String(),
'ext_code': Integer()
}
web_url = String()
id_ = String()
public = Boolean()
for_profit = Boolean()
offers_degree = Boolean()
other_names = String()
def save(self, **kwargs):
self.meta.id = self.id_
return super(Institution, self).save(**kwargs)
class Meta:
index = ELASTIC_INST_INDEX