faker icon indicating copy to clipboard operation
faker copied to clipboard

New feature for get realistic words according a context

Open dhfherna opened this issue 1 year ago • 2 comments

Description My solution consists in consuming an API that allows to query a list of words related to a context, for example, for the context of a pastry shop, we can receive the following result: List: pastry, pastrycook, patissier,: bakeshop, confectionary, cakery, pastry chef, pastrymaker, pasteler, bakery, pastrymaking, boulangerie, croissanterie, bakehouse, cake shop, pieshop, doughnutery, baker's, paste Or if you prefer, a single random word from this list: pastrymaker

Are you trying to fix an existing issue?

#143

Go Version

$ go version
go version go1.21.3 linux/amd64

Go Tests

$ go test
2023/10/30 11:27:12 Error while requesting https://loremflickr.com/300/200 : request failed
2023/10/30 11:27:13 Error while creating a temp file: temp file creation failed
2023/10/30 11:27:13 Error while requesting https://randomuser.me : request failed
2023/10/30 11:27:13 Error while creating a temp file: temp file creation failed
PASS
ok      github.com/jaswdr/faker 5.128s

dhfherna avatar Oct 30 '23 16:10 dhfherna

Hello @dhfherna

It is probably best not to make network calls to solve this problem.

Making API requests to a third party service can fail or behave unexpectedly.

ayoubfaouzi avatar Oct 31 '23 19:10 ayoubfaouzi

@dhfherna thank you for the PR, although as @LordNoteworthy unfortunately there are many problems that arise when using external services, to start, the machine running the code could not have access to the internet. There is also no guaranteed that the external service will be available, imagine that your code fail because of that, is definitely not a good experience to have. We have similar issues on transient failures in our own tests because we use external services to generate images (which I'm planning to remove in the future).

As alternative, can you move the logic and data to the file itself?

jaswdr avatar Nov 07 '23 11:11 jaswdr