Skip to content

Commit

Permalink
Updated PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Oct 1, 2019
1 parent 8bc12d3 commit 77e7d1b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 56 deletions.
48 changes: 22 additions & 26 deletions bothub/api/v2/nlp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,43 +421,39 @@ def retrieve(self, request, *args, **kwargs):
update = self.get_object()

regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|'
r'[A-Z0-9-]{2,}\.?)|'
r'localhost|'
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
r'(?::\d+)?'
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
r"^(?:http|ftp)s?://" # http:// or https://
r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|"
r"[A-Z0-9-]{2,}\.?)|"
r"localhost|"
r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
r"(?::\d+)?"
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)

if re.match(regex, update.bot_data) is not None:
try:
download = requests.get(update.bot_data)
bot_data = base64.b64encode(download.content)
except Exception:
bot_data = b''
bot_data = b""
else:
bot_data = update.bot_data
return Response({
'update_id': update.id,
'repository_uuid': update.repository.uuid,
'bot_data': str(bot_data)
})
return Response(
{
"update_id": update.id,
"repository_uuid": update.repository.uuid,
"bot_data": str(bot_data),
}
)

def create(self, request, *args, **kwargs):
check_auth(request)
id = request.data.get('id')
repository = get_object_or_404(
RepositoryUpdate,
pk=id
)
id = request.data.get("id")
repository = get_object_or_404(RepositoryUpdate, pk=id)
if settings.AWS_SEND:
bot_data = base64.b64decode(request.data.get('bot_data'))
repository.save_training(
send_bot_data_file_aws(
id,
bot_data
)
)
bot_data = base64.b64decode(request.data.get("bot_data"))
repository.save_training(send_bot_data_file_aws(id, bot_data))
else:
repository.save_training(request.data.get('bot_data'))
repository.save_training(request.data.get("bot_data"))
return Response({})
15 changes: 6 additions & 9 deletions bothub/common/migrations/0035_auto_20190902_1455.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@

def update_repository(apps, schema_editor):
if settings.AWS_SEND:
for update in RepositoryUpdate.objects.all().exclude(bot_data__exact=''):
for update in RepositoryUpdate.objects.all().exclude(bot_data__exact=""):
repository_update = RepositoryUpdate.objects.get(pk=update.pk)
bot_data = send_bot_data_file_aws(update.pk, update.bot_data)
repository_update.bot_data = bot_data
repository_update.save(
update_fields=[
'bot_data',
])
print('Updating bot_data repository_update {}'.format(str(update.pk)))
repository_update.save(update_fields=["bot_data"])
print("Updating bot_data repository_update {}".format(str(update.pk)))


class Migration(migrations.Migration):
Expand All @@ -25,8 +22,8 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(update_repository),
migrations.AlterField(
model_name='repositoryupdate',
name='bot_data',
field=models.TextField(blank=True, verbose_name='bot data'),
model_name="repositoryupdate",
name="bot_data",
field=models.TextField(blank=True, verbose_name="bot data"),
),
]
14 changes: 3 additions & 11 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,9 @@ class Meta:
)
use_competing_intents = models.BooleanField(default=False)
use_name_entities = models.BooleanField(default=False)
created_at = models.DateTimeField(
_('created at'),
auto_now_add=True)
bot_data = models.TextField(
_('bot data'),
blank=True)
by = models.ForeignKey(
User,
models.CASCADE,
blank=True,
null=True)
created_at = models.DateTimeField(_("created at"), auto_now_add=True)
bot_data = models.TextField(_("bot data"), blank=True)
by = models.ForeignKey(User, models.CASCADE, blank=True, null=True)
training_started_at = models.DateTimeField(
_("training started at"), blank=True, null=True
)
Expand Down
20 changes: 10 additions & 10 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
CSRF_COOKIE_SECURE=(bool, False),
SUPPORTED_LANGUAGES=(cast_supported_languages, "en|pt"),
CHECK_ACCESSIBLE_API_URL=(str, None),
BOTHUB_ENGINE_AWS_ACCESS_KEY_ID=(str, ''),
BOTHUB_ENGINE_AWS_SECRET_ACCESS_KEY=(str, ''),
BOTHUB_ENGINE_AWS_S3_BUCKET_NAME=(str, ''),
BOTHUB_ENGINE_AWS_REGION_NAME=(str, 'us-east-1'),
BOTHUB_ENGINE_AWS_SEND=(bool, False)
BOTHUB_ENGINE_AWS_ACCESS_KEY_ID=(str, ""),
BOTHUB_ENGINE_AWS_SECRET_ACCESS_KEY=(str, ""),
BOTHUB_ENGINE_AWS_S3_BUCKET_NAME=(str, ""),
BOTHUB_ENGINE_AWS_REGION_NAME=(str, "us-east-1"),
BOTHUB_ENGINE_AWS_SEND=(bool, False),
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -258,8 +258,8 @@


# AWS
AWS_SEND = env.bool('BOTHUB_ENGINE_AWS_SEND')
AWS_ACCESS_KEY_ID = env.str('BOTHUB_ENGINE_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env.str('BOTHUB_ENGINE_AWS_SECRET_ACCESS_KEY')
AWS_BUCKET_NAME = env.str('BOTHUB_ENGINE_AWS_S3_BUCKET_NAME')
AWS_REGION_NAME = env.str('BOTHUB_ENGINE_AWS_REGION_NAME')
AWS_SEND = env.bool("BOTHUB_ENGINE_AWS_SEND")
AWS_ACCESS_KEY_ID = env.str("BOTHUB_ENGINE_AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env.str("BOTHUB_ENGINE_AWS_SECRET_ACCESS_KEY")
AWS_BUCKET_NAME = env.str("BOTHUB_ENGINE_AWS_S3_BUCKET_NAME")
AWS_REGION_NAME = env.str("BOTHUB_ENGINE_AWS_REGION_NAME")

0 comments on commit 77e7d1b

Please sign in to comment.