Skip to content

Conversation

@rafael-hs
Copy link
Owner

Valei-me

@@ -0,0 +1,63 @@
defmodule GithubWebscraping.ExtractFileInfos do
def fetch_file_name(html) do
file_name =

Choose a reason for hiding this comment

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

não precisa atribuir a var se vc ja esta retornando o resultado da ultima linha da função

Choose a reason for hiding this comment

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

+1

Copy link
Owner Author

Choose a reason for hiding this comment

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

boa

Copy link

@rfsbarreto rfsbarreto left a comment

Choose a reason for hiding this comment

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

Já ouviu falar em teste irmao?

|> Floki.text()

cond do
String.contains?(string_bytes, "KB") ->

Choose a reason for hiding this comment

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

EU prefiro usar pattern matching ao inves de conds. entao criaria uma funcao auxiliar pra lidar com essas diferencas de codigo ai

Copy link
Owner Author

Choose a reason for hiding this comment

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

como eu iria fazer isso com pattern ? tem algum exemplo ?

Choose a reason for hiding this comment

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

def get_number_bytes(string_bytes, "MB")
def get_number_bytes(string_bytes, "KB" )
def get_number_bytes(string_bytes, "GB" )
def get_number_bytes(string_bytes, "Bytes" )

E nessa linha ao inves de fazer o cond, vc faz:
get_number_bytes( string_bytes, String.contains?(string_bytes, "MB"))

Aproveitando, as linhas 1 e 2 de cada umas das conds sao iguais, ou seja, duplicidade de código que dá pra ser extraida pra funcoes novas :)

"""
alias GithubWebscraping.MappingRepository

defdelegate get_repository_infos(url), to: MappingRepository, as: :process

Choose a reason for hiding this comment

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

DAve thomas dorme feliz

end

defp get_all_lines(files) do
all_lines = Enum.reduce(files, 0, fn file, acc -> file.file_lines + acc end)

Choose a reason for hiding this comment

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

n precisa de duas linhas, nome do metodo já é suficiente pra entender

end

defp get_all_bytes(files) do
all_bytes = Enum.reduce(files, 0, fn file, acc -> file.file_bytes + acc end)

Choose a reason for hiding this comment

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

mesma coisa do comentario acima

Enum.filter(urls, fn url -> url =~ "tree" end)
end

defp is_first_url(url) do

Choose a reason for hiding this comment

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

nome do metodo ta ruim.

Choose a reason for hiding this comment

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

first_url?(url) seria uma forma mais elixirzada, certo?

Enum.filter(urls, fn url -> url =~ "blob" end)
end

defp get_pastes_url(urls) do

Choose a reason for hiding this comment

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

get_directories_urls*
ALO CAMBLY

Choose a reason for hiding this comment

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

Paste

Copy link
Owner Author

Choose a reason for hiding this comment

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

em minha defesa existe essa palavra em inglês

@@ -0,0 +1,63 @@
defmodule GithubWebscraping.ExtractFileInfos do

Choose a reason for hiding this comment

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

Esse modulo recebe um arquivo html ne ? olhando as funções, talvez daria pra chamar só de File. HTMLFile.get_name

Copy link

@vivialima vivialima left a comment

Choose a reason for hiding this comment

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

Faltou testinhos, masss boaa 🚀

@@ -0,0 +1,8 @@
defmodule Lib.GithubWebscraping do

Choose a reason for hiding this comment

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

ficaram 2 arquivos com o mesmo nome. Talvez esse poderia ser só NomeDoProjeto.Api mesmo

bytes * 1_000_000.0

String.contains?(string_bytes, "Bytes") ->
bytes = String.trim(List.last(List.last(Regex.scan(~r/(\d+)/, string_bytes))))

Choose a reason for hiding this comment

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

Dava pra ter usado |>

@derive {Jason.Encoder, only: [:file_url, :file_name, :extension, :file_bytes, :file_lines]}
defstruct [:file_url, :file_name, :extension, :file_bytes, :file_lines]

def build(file_url, file_name, extension, file_bytes, file_lines) do

Choose a reason for hiding this comment

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

O elixir tem uma função struct(%GithubFile{}, [key: value]) que retorna um struct. Não precisaria do build


alias Lib.GithubWebscraping

def index(conn, %{"github_url" => github_url}) do

Choose a reason for hiding this comment

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

Essa rota seria index mesmo? ou show recebendo url? user_path GET /users/:id HelloWeb.UserController :show

Choose a reason for hiding this comment

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


@spec process(String.t()) :: map()
def process(url) do
files = mapping_repository_by_url(url)

Choose a reason for hiding this comment

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

|>

end

defp mapping_repository_by_url(url) do
urls = get_urls(is_first_url(url))

Choose a reason for hiding this comment

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

|>


other_files =
if Enum.count(pastes_url) > 0 do
Enum.map(pastes_url, fn url ->

Choose a reason for hiding this comment

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

💅 Enum.map(dirs, &mapping_repository_by_url/1)

@@ -0,0 +1,84 @@
defmodule GithubWebscraping.MappingRepository do

Choose a reason for hiding this comment

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

não sei se entendi o Mapping no nome. O que acha de algo como ExtractRepositoryInfo.run ...

Comment on lines +15 to +21
html
|> Floki.find("div.repository-content")
|> Floki.find("div.d-flex.flex-items-start.flex-shrink-0")
|> Floki.find("strong.final-path")
|> Floki.text()

Path.extname(file_name)

Choose a reason for hiding this comment

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

Isso seria o mesmo que:

  html
  |> Floki.find(...)
  |> Floki.find(...)
  |> Floki.find(...)
  |> Floki.text()
  |> Path.extname()

?

Copy link
Owner Author

Choose a reason for hiding this comment

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

sim

Comment on lines +24 to +27
IO.puts("\n----------Returned files----------\n")
IO.inspect(files)
IO.puts("\n----------Returned urls-----------\n")
IO.inspect(pastes_url)

Choose a reason for hiding this comment

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

Eu n sei o quanto essa opinião vale num projeto Elixir, mas se eu estivesse fazendo isso em OO, criaria uma classe separada para lidar com "apresentação". Basicamente um Presenter, ou View.

Provavelmente faria um módulo separado para agrupar essa responsabilidade de output

Copy link
Owner Author

Choose a reason for hiding this comment

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

eu só coloquei isso para testes mesmo

Copy link
Owner Author

Choose a reason for hiding this comment

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

mas bom ponto de qualquer forma

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.

5 participants