Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored ymt2/python-face-client #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/python-face-client master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -11 to +18
fp = open(os.path.join(cwd, 'face_client', '__init__.py'))

version = None
for line in fp:
match = version_re.search(line)
if match:
version = eval(match.group(1))
break
else:
raise Exception('Cannot find version in __init__.py')
fp.close()

with open(os.path.join(cwd, 'face_client', '__init__.py')) as fp:
version = None
for line in fp:
if match := version_re.search(line):
version = eval(match[1])
break
else:
raise Exception('Cannot find version in __init__.py')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-22 refactored with the following changes:

raise IOError('File %s does not exist' % (file))
raise IOError(f'File {file} does not exist')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.faces_detect refactored with the following changes:

Comment on lines -98 to +103
self.__check_user_auth_credentials(uids)
self.__check_user_auth_credentials(uids)

data = {'uids': uids}
self.__append_user_auth_data(data, facebook_uids, twitter_uids)
self.__append_optional_arguments(data, namespace=namespace)

response = self.send_request('faces/status', data)
return response
return self.send_request('faces/status', data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.faces_status refactored with the following changes:

Comment on lines -123 to +138
self.__check_user_auth_credentials(uids)
self.__check_user_auth_credentials(uids)

data = {'uids': uids}

if file:
# Check if the file exists
if not os.path.exists(file):
raise IOError('File %s does not exist' % (file))
raise IOError(f'File {file} does not exist')

data.update({'file': file})
data['file'] = file
else:
data.update({'urls': urls})
data['urls'] = urls

self.__append_user_auth_data(data, facebook_uids, twitter_uids)
self.__append_optional_arguments(data, train=train,
namespace=namespace)

response = self.send_request('faces/recognize', data)
return response
return self.send_request('faces/recognize', data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.faces_recognize refactored with the following changes:

Comment on lines -154 to +157
self.__check_user_auth_credentials(uids)
self.__check_user_auth_credentials(uids)

data = {'uids': uids}
self.__append_user_auth_data(data, facebook_uids, twitter_uids)
self.__append_optional_arguments(data, namespace=namespace)

response = self.send_request('faces/train', data)
return response
return self.send_request('faces/train', data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.faces_train refactored with the following changes:

Comment on lines -296 to +289
data.update({'user_auth': 'fb_user:%s,fb_session:%s' %
(self.facebook_credentials['fb_user'],
self.facebook_credentials['fb_session'])})
data.update(
{
'user_auth': f"fb_user:{self.facebook_credentials['fb_user']},fb_session:{self.facebook_credentials['fb_session']}"
}
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.__append_user_auth_data refactored with the following changes:

Comment on lines -323 to +322
url = '%s/%s' % (API_URL, method)
url = f'{API_URL}/{method}'

data = {'api_key': self.api_key,
'api_secret': self.api_secret,
'format': self.format}

if parameters:
data.update(parameters)
data |= parameters
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaceClient.send_request refactored with the following changes:

Comment on lines -51 to +58
if self._filename == None:
self._headers[Part.CONTENT_DISPOSITION] = \
('form-data; name="%s"' % self._name)
if self._filename is None:
self._headers[Part.CONTENT_DISPOSITION] = f'form-data; name="{self._name}"'
self._headers.setdefault(Part.CONTENT_TYPE,
Part.DEFAULT_CONTENT_TYPE)
else:
self._headers[Part.CONTENT_DISPOSITION] = \
('form-data; name="%s"; filename="%s"' %
(self._name, self._filename))
self._headers[
Part.CONTENT_DISPOSITION
] = f'form-data; name="{self._name}"; filename="{self._filename}"'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Part.__init__ refactored with the following changes:

Comment on lines -74 to +75
lines = []
lines.append('--' + Part.BOUNDARY)
for (key, val) in self._headers.items():
lines.append('%s: %s' % (key, val))
lines.append('')
lines.append(self._body)
lines = [f'--{Part.BOUNDARY}']
lines.extend(f'{key}: {val}' for key, val in self._headers.items())
lines.extend(('', self._body))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Part.get refactored with the following changes:

Comment on lines -145 to +144
all.append('--' + Part.BOUNDARY + '--')
all.append(f'--{Part.BOUNDARY}--')
all.append('')
# We have to return the content type, since it specifies the boundary.
content_type = 'multipart/form-data; boundary=%s' % Part.BOUNDARY
content_type = f'multipart/form-data; boundary={Part.BOUNDARY}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Multipart.get refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant