Skip to content

Commit 730c8dc

Browse files
committed
Upgrade to Python3
1 parent c07dd20 commit 730c8dc

File tree

14 files changed

+29
-32
lines changed

14 files changed

+29
-32
lines changed

.travis.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
language: python
22
python:
3-
- "2.7"
4-
- "3.3"
5-
- "3.4"
6-
- "3.5"
7-
- "3.6"
8-
- "nightly"
3+
- "3.7"
94
# command to install dependencies
105
install:
116
- pip install -r requirements.txt

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM python:2.7
1+
FROM python:3.7
22
ENV DEBIAN_FRONTEND noninteractive
33

44
COPY . /htools-api
55

66
WORKDIR /htools-api
77

88
RUN pip install --upgrade pip
9-
RUN pip install -r requirements.txt
9+
RUN pip install -r requirements.txt && pip install --upgrade requests
1010
RUN pip install -e .
1111

1212
EXPOSE 8000

healthtools/commands.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from future import standard_library
2+
standard_library.install_aliases()
13
from elasticsearch import helpers
2-
import urllib2, json
4+
import urllib.request, urllib.error, urllib.parse, json
35
from flask.cli import AppGroup
46

57
from healthtools.manage import app
@@ -10,7 +12,7 @@
1012
@htools_cli.command('loaddata')
1113
def load_data():
1214
url = 'https://s3-eu-west-1.amazonaws.com/cfa-healthtools-ke/data/doctors.json'
13-
response = urllib2.urlopen(url)
15+
response = urllib.request.urlopen(url)
1416
helpers.bulk(es, json.load(response), index=es_index, doc_type='doctors')
1517

1618
@htools_cli.command('resetindex')

healthtools/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str
12
import logging
23

34
from werkzeug.local import LocalProxy
@@ -63,5 +64,5 @@ def get_es_index():
6364
class AWS4AuthNotUnicode(AWS4Auth):
6465
def __call__(self, req):
6566
req = super(AWS4AuthNotUnicode, self).__call__(req)
66-
req.headers = {str(name): value for name, value in req.headers.items()}
67+
req.headers = {str(name): value for name, value in list(req.headers.items())}
6768
return req

healthtools/search/clinicalofficers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from builtins import str
2+
from builtins import zip
13
import requests
24
import logging
35
from bs4 import BeautifulSoup
@@ -20,8 +22,6 @@ def get_clinical_officers(query):
2022
clinicalofficers = {'hits': [], 'total': 0}
2123
try:
2224
response = requests.post(COC_REGISTER_URL, data = {'search_register':'1', 'search_text': query})
23-
if 'No results' in response.content:
24-
return clinicalofficers
2525

2626
# make soup for parsing out of response and get the table
2727
soup = BeautifulSoup(response.content, 'html.parser')

healthtools/search/elastic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str
12
import logging
23
from healthtools.core import es, es_index
34

healthtools/search/nurses.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from builtins import str
2+
from builtins import zip
13
import requests
24
import logging
35
from bs4 import BeautifulSoup
@@ -20,9 +22,7 @@ def get_people(query):
2022
people = {'hits': [], 'total': 0}
2123
try:
2224
response = requests.post(FETCH_URL, data = {'search_register':'1', 'search_text': query})
23-
if 'No results' in response.content:
24-
return people
25-
25+
2626
# make soup for parsing out of response and get the table
2727
soup = BeautifulSoup(response.content, 'html.parser')
2828
table = soup.find('table', {'class': 'datatables'}).find('tbody')

healthtools/search/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def determine_doc_type_using_wit(query, doc_type=None):
8181
message_text = query
8282
resp = client.message(message_text)
8383
query = ''.join(nested_lookup('value', resp['entities']['query']))
84-
doc_type = ''.join([var for var in (resp['entities'].keys()) if var != 'query'])
84+
doc_type = ''.join([var for var in (list(resp['entities'].keys())) if var != 'query'])
8585
doc_type = doc_type.replace("_", "-") # changes underscore to hyphen
8686
if doc_exists(doc_type) == True:
8787
return doc_type, query

healthtools/sms/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str
12
import logging
23

34
from healthtools.sms import twilio, mtech

healthtools/tests/nurse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_nurses_endpoint_can_retrieve_cached_result(self):
4343
self.client.get("search/nurses?q=Marie")
4444
# second time should retrieve cached result
4545
response = self.client.get("search/nurses?q=Marie")
46-
self.assertIn(b"X-Retrieved-From-Cache", response.headers.keys())
46+
self.assertIn(b"X-Retrieved-From-Cache", list(response.headers.keys()))
4747

4848
def test_nurses_endpoint_with_bad_endpoint(self):
4949
"""

0 commit comments

Comments
 (0)