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

Corrige chaves de tradução para Pipo Saude #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Vagas de empresas que ativamente contratam pessoas desenvolvedoras Clojure no Br

## Vagas


| Vaga | Empresa | Local | Remoto? | Onde aplicar |
| Vaga | Empresa | Local | Remoto? | Onde se candidatar |
|-------------------------------------------------------|--------------|-----------|---------|----------------------------------------------------------------------------------------------------|
| Full Stack Developer | Flow Finance | | Sim | https://airtable.com/embed/shrG8DnjAdAOAZm9h/tble1ghQMefhblMVK/viwOzu3raZSmdxK7Z/recGtRyuHlvFhUV0v |
| Business Security Manager | Nubank | São Paulo | Não | https://boards.greenhouse.io/nubank/jobs/3400816 |
Expand Down
4 changes: 3 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
enlive/enlive {:mvn/version "1.1.6"}
selmer/selmer {:mvn/version "1.12.31"}}}
selmer/selmer {:mvn/version "1.12.31"}
org.mozilla/rhino {:mvn/version "1.7.13"}
clj-http/clj-http {:mvn/version "3.12.3"}}}
15 changes: 12 additions & 3 deletions src/clojure_empregos_brasil/boards.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns clojure-empregos-brasil.boards
(:require [net.cgrand.enlive-html :as html]
[clojure-empregos-brasil.scrap :as scrap]))
[clojure-empregos-brasil.scrap :as scrap]
[clojure-empregos-brasil.breezy :as breezy]))

(def gupy
{:title [:.title html/text-node]
Expand All @@ -21,6 +22,14 @@
(def breezy
Copy link

Choose a reason for hiding this comment

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

creio que esse breezy aqui tá dando um "shadow" no require, não? De qualquer forma, é ambíguo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Concordo, vou pensar numa boa alternativa.

{:title [:h2 html/text-node]
:url #(-> % (html/select [:a]) first :attrs :href)
:location [:ul.meta :li.location html/text-node]
:location #(-> %
(html/select [:ul.meta :li.location html/text-node])
first
breezy/i18n)
:department [:ul.meta :li.department html/text-node]
:type [:ul.meta :li.type html/text-node]})
:type [:ul.meta :li.type html/text-node]
:remote #(-> %
(html/select [:ul.meta :li.location html/text-node])
(->> first (contains? #{"%LABEL_POSITION_TYPE_REMOTE%"
"%LABEL_POSITION_TYPE_Worldwide%"
"%LABEL_POSITION_TYPE_WORLDWIDE%"})))})
89 changes: 89 additions & 0 deletions src/clojure_empregos_brasil/breezy.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
(ns clojure-empregos-brasil.breezy
(:require [net.cgrand.enlive-html :as html]
[clj-http.client :as http])
(:import [org.mozilla.javascript CompilerEnvirons Context Parser Token]
[org.mozilla.javascript.ast NodeVisitor]))

(def ^:private i18n-map (atom nil))

(defn- parse-js
[source uri]
(let [env (new CompilerEnvirons)]
(.setLanguageVersion env Context/VERSION_ES6)

(-> (Parser. env)
(.parse source uri 0))))

(defn- translation-var?
[node]
(let [node (.getTarget node)]
(and (= (.getType node) Token/NAME)
(= (.getIdentifier node) "TRANSLATIONS"))))

(defn- make-visitor
[target]
(reify NodeVisitor
(visit [this node]
(if (= (.getType node) Token/VAR)
(do
(when-let [node (first (filter translation-var? (.getVariables node)))]
(reset! target (.getInitializer node)))
false)
true))))

(defn- find-translation-node
[ast]
(let [translation-node (atom nil)
visitor (make-visitor translation-node)]
(.visitAll ast visitor)
@translation-node))

(defn- node->str
[node]
(let [type (.getType node)]
(cond
(= type Token/NAME) (.getIdentifier node)
(= type Token/STRING) (.getValue node)
(= type Token/NUMBER) (.getValue node)
:else nil)))

(def object-literal->hashmap)

(defn- element->pair
[element]
(let [left (.getLeft element)
right (.getRight element)]
[(node->str left) (if (= (.getType right) Token/OBJECTLIT)
(object-literal->hashmap right)
(node->str right))]))

(defn- object-literal->hashmap
[literal]
(if (not= (.getType literal) Token/OBJECTLIT)
nil
(into {} (map element->pair (.getElements literal)))))

(defn- translate-script-src
[page]
(-> page (html/select [:#translateScript]) first :attrs :src))

(defn- fetch-script
[url]
(-> url http/get :body))

(defn load-i18n
[page]
(let [translate-script (translate-script-src page)]
(reset! i18n-map
(-> translate-script
fetch-script
(parse-js translate-script)
find-translation-node
object-literal->hashmap
(get "pt-br")))))


(defn i18n
[key]
(get @i18n-map key key))

11 changes: 6 additions & 5 deletions src/clojure_empregos_brasil/companies.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns clojure-empregos-brasil.companies
(:require [clojure.string :as string]
[clojure-empregos-brasil.boards :as boards]))
[clojure-empregos-brasil.boards :as boards]
[clojure-empregos-brasil.breezy :as breezy]))

(def nubank
{:name "Nubank"
Expand All @@ -9,8 +10,7 @@
:scrap boards/greenhouse
:engineer? (comp (partial = "60350") :department)
:brazil? (comp (partial = "58102") :office_id)
:clojure? boolean
:enrich identity})
:clojure? boolean})

(def paygo
{:name "PayGo"
Expand Down Expand Up @@ -41,7 +41,8 @@
:scrap boards/breezy
:engineer? #(= (:department %) "Engenharia")
:brazil? boolean
:clojure? boolean})
:clojure? boolean
:pre-html #(do (breezy/load-i18n %) %)})

(def i80-seguros
{:name "180° Seguros"
Expand All @@ -50,4 +51,4 @@
:scrap boards/breezy
:engineer? #(= (:department %) "Tecnologia")
:brazil? boolean
:clojure? boolean})
:clojure? boolean})
4 changes: 2 additions & 2 deletions src/clojure_empregos_brasil/scrap.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
sequence."
[& companies]
(flatten
(for [{:keys [engineer? brazil? clojure? enrich name page] :as company} companies]
(for [{:keys [engineer? brazil? clojure? pre-html name page] :as company} companies]
(let [html (html/html-resource (URL. page))
positions (scrap html
positions (scrap (if (fn? pre-html) (pre-html html) html)
(:path company)
(:scrap company))]
(->> positions
Expand Down