-
Notifications
You must be signed in to change notification settings - Fork 0
commit for comments #2
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,63 @@ | |||
| defmodule GithubWebscraping.ExtractFileInfos do | |||
| def fetch_file_name(html) do | |||
| file_name = | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boa
rfsbarreto
left a comment
There was a problem hiding this 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") -> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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
vivialima
left a comment
There was a problem hiding this 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 | |||
There was a problem hiding this comment.
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)))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 ...
| 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) |
There was a problem hiding this comment.
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()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sim
| IO.puts("\n----------Returned files----------\n") | ||
| IO.inspect(files) | ||
| IO.puts("\n----------Returned urls-----------\n") | ||
| IO.inspect(pastes_url) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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

Valei-me