Skip to content

Commit

Permalink
Merge pull request #93 from Algolytics/windows-encoding-support
Browse files Browse the repository at this point in the history
proper windows encoding support on linux machine
  • Loading branch information
lszpak authored Jul 13, 2018
2 parents c081249 + 16c7e70 commit 1517ef3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Create new job

job = dq.submit_job(job_config, input_data=input_data) # with data in a variable

job = dq.submit_job(job_config, input_file='my_file.csv', input_file_encoding='windows-1250') # with data inside file
job = dq.submit_job(job_config, input_file='my_file.csv') # with data inside file

print(job.id)
print(job.name)
Expand Down Expand Up @@ -97,7 +97,7 @@ Create new deduplication job
job_config.module_std(address=True, names=True, contact=True)
job_config.extend(gus=True, geocode=True, diagnostic=True)

job = dq.submit_job(job_config, input_data=input_data)
job = dq.submit_job(job_config, input_data=input_data)

print(job)
...
Expand Down Expand Up @@ -176,7 +176,7 @@ Analogously for other modules:
* NIP
* REGON


Check job state
---------------
::
Expand Down
2 changes: 1 addition & 1 deletion dq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

__author__ = """Mikołaj Olszewski"""
__email__ = 'mikolaj.olszewski@algolytics.pl'
__version__ = '0.4.0'
__version__ = '0.5.0'

__all__ = ['DQClient', 'JobConfig']
13 changes: 5 additions & 8 deletions dq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def list_jobs(self):
return self.request_client.get('/jobs')

@from_response(Job)
def submit_job(self, config, input_data=None, input_file=None,
input_file_encoding='utf-8'):
def submit_job(self, config, input_data=None, input_file=None):
""" POST 'https://app.dataquality.pl/api/v1/jobs' """
parts = {
'config': {
Expand All @@ -41,9 +40,7 @@ def submit_job(self, config, input_data=None, input_file=None,
if input_data:
parts['file']['content'] = str(input_data)
else:
parts['file']['content'] = open(input_file, 'r',
encoding=input_file_encoding)

parts['file']['content'] = open(input_file, 'rb')
return self.request_client.post_multipart('/jobs', parts=parts)

def job_state(self, job_id):
Expand All @@ -61,13 +58,13 @@ def job_report(self, job_id):
""" GET 'https://app.dataquality.pl/api/v1/jobs/{{job_id}}' """
return self.request_client.get('/jobs/{}'.format(job_id))

def job_results(self, job_id, out_file=None, code_page = 'utf-8'):
def job_results(self, job_id, out_file=None, encoding='utf-8'):
""" GET 'https://app.dataquality.pl/api/v1/jobs/{{job_id}}/result' """
response = self.request_client.get('/jobs/{}/result'.format(job_id))
response = self.request_client.get('/jobs/{}/result'.format(job_id), encoding=encoding)
if not response.is_ok():
raise DQError(status=response.status, message=response.content)
if out_file:
with open(out_file, 'w', encoding=code_page) as file:
with open(out_file, 'w', encoding=encoding) as file:
file.write(response.content)

def delete_job(self, job_id):
Expand Down
3 changes: 2 additions & 1 deletion dq/request_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def __init__(self, base_url, token):
def __make_url(self, path):
return '{}/{}'.format(self.base_url, path)

def get(self, path, headers={}):
def get(self, path, headers={}, encoding=None):
response = self.session.get(self.__make_url(path), headers=headers)
response.encoding = encoding
return Response('GET', response.status_code, response.text)

def post(self, path, headers={}):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.0
current_version = 0.5.0
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='dq-client',
version='0.4.0',
version='0.5.0',
description="Python library which allows to use http://dataquality.pl in easy way.",
long_description=readme + '\n\n' + history,
author="Mikołaj Olszewski",
Expand Down

0 comments on commit 1517ef3

Please sign in to comment.