From 26c984690871b20c42237cbae2b5ee39cb2ba020 Mon Sep 17 00:00:00 2001 From: Leo Gassman Date: Sun, 29 Dec 2024 20:23:25 -0300 Subject: [PATCH] first commit --- .github/workflows/ci.yml | 14 ++++++ .gitignore | 6 +++ README.md | 6 +++ assets/dolarito.gif | Bin 0 -> 1045 bytes dolarito.ts | 43 ++++++++++++++++ dolarito.wlk | 43 ++++++++++++++++ mainDolarito.wpgm | 18 +++++++ package-lock.json | 106 +++++++++++++++++++++++++++++++++++++++ package.json | 8 +++ 9 files changed, 244 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 assets/dolarito.gif create mode 100644 dolarito.ts create mode 100644 dolarito.wlk create mode 100644 mainDolarito.wpgm create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8e84736 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,14 @@ +name: build + +on: [push, pull_request] +jobs: + wollok-ts: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - run: | + wget -O wollok-ts-cli https://github.com/uqbar-project/wollok-ts-cli/releases/latest/download/wollok-ts-cli-linux-x64 + chmod a+x ./wollok-ts-cli + ./wollok-ts-cli test --skipValidations -p ./ + shell: bash diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e95028 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ + +# Local history +.history + +# Wollok Log +*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f6846c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ + + +## dolarito + +TODO + diff --git a/assets/dolarito.gif b/assets/dolarito.gif new file mode 100644 index 0000000000000000000000000000000000000000..d404deb98cba21078411c59a1ba5a2233e040964 GIT binary patch literal 1045 zcmZ?wbhEHbbYO5`I2Ou~HPtM0nrRjYnPpBl%>p5_tQlt6AY`6B%OYo%dCnY*oH>?- z3vFAcRTeF_D_UY(w8XAxsoj(rv&&XFm92KFSmRu|!L@3mTh&JQY9P7Et!A@F^%nQq zt)8{pyc%|T*YEOf03n~oJ-&^5eVg|AHSPCn-tXVMKcEGO4g|Ix4DLJ>-gziu-L7Rb zPUX%#oj>bz{v{9UVVA^=Ii4( zU!VN``}5D=U;qC7{r~^p|A7XI{{)?jQWHy3QxwWGOEMJPJ$(Zh6o0ZXaxv61=r8~Q zD54nH|25P%HMg|3wRd!Ob@%l4^-q{MY4Vh*)27duIcxTux%1{v&|0*3$Ri;<;!P|Ub%5& zKjWRd_wL`nw)er4C%2!zxbtYw%a_j?#Xf%e{N>~8-CuuxzWe^1=J#EHKJGRRkUWrl zj_X=b$D0M~Tkib2E2Q*fnscP8Ma+%`3t0@>Hajev5xCTgCz{XMMc{!i1B)Pw@-d!( zZr4eZLRW|cI-XW+Dq^>}AvCi|v0p1_ipInsRrmAFFWG7$G>S7qBmGugnUK1eYw~i2 z+lCg7-5Q5ALSs&3Ii_&jsQ&ksDM6!ps-ACDz^WS&Y+L6t?-ok`>aglbJI|Eb%bE-} zo2PLp1$zZq2AxifVeVObZ>{LzjcLvYCkMD`sjWRz9CsVfWzq{06pP4D(yW cxK1tXP+Rq4QIFZH7mFvjX{}UgWMHrc07TDHQ2+n{ literal 0 HcmV?d00001 diff --git a/dolarito.ts b/dolarito.ts new file mode 100644 index 0000000..3bac012 --- /dev/null +++ b/dolarito.ts @@ -0,0 +1,43 @@ +let resultado:string | undefined + +const dolarApi = { + *request(this: any, self: any) : any { + resultado = undefined + try { + buscarCotizacion((res: string) => { + resultado = res + }) + } + catch (error) { + resultado = `Error: ${error}` + } + }, + + *response(this:any, self:any): any { + return this.reify(resultado) + }, +} + +function buscarCotizacion(callback: (resultado: string) => void): void { + const apiUrl = 'https://api.bluelytics.com.ar/v2/latest' + + fetch(apiUrl) + .then(response => { + if (!response.ok) { + callback(`Error ${response}`) + return + } + return response.json() + }) + .then(data => { + const compraBlue = data.blue.value_buy + const ventaBlue = data.blue.value_sell + callback(`Dólar Blue - Compra: $${compraBlue}, Venta: $${ventaBlue}`) + }) + .catch(error => { + callback(`Error: ${error}`) + }) +} + + +export { dolarApi } \ No newline at end of file diff --git a/dolarito.wlk b/dolarito.wlk new file mode 100644 index 0000000..bc3b174 --- /dev/null +++ b/dolarito.wlk @@ -0,0 +1,43 @@ +import wollok.game.* + +object buscando { + method text() = "BUSCANDO" + method buscar(owner) { self.error ("Ya estoy buscando")} + + method buscarResultado(owner) { + const r = dolarApi.response() + if (r != null) { + game.removeTickEvent("RESULTADO") + owner.estado(new Libre(text=r)) + } + } + +} + +class Libre { + var property text = "Apretá enter!" + method buscar(owner) { + owner.estado(buscando) + dolarApi.request() + game.onTick(1,"RESULTADO", { buscando.buscarResultado(owner) } ) + } + +} + +object dolarito { + + var property estado = new Libre() + var property position = game.center() + + method image() = "dolarito.gif" + method text() = estado.text() + + method buscar() { + estado.buscar(self) + } +} + +object dolarApi { + method request() native + method response() native +} \ No newline at end of file diff --git a/mainDolarito.wpgm b/mainDolarito.wpgm new file mode 100644 index 0000000..207e840 --- /dev/null +++ b/mainDolarito.wpgm @@ -0,0 +1,18 @@ +import wollok.game.* + +import dolarito.dolarito + +program Doralito { + game.title("Dolarito") + game.height(10) + game.width(10) + + game.addVisualCharacter(dolarito) + + keyboard.enter().onPressDo({ + dolarito.buscar() + }) + + + game.start() +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..43e8257 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,106 @@ +{ + "name": "dolarito", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "dolarito", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "node-fetch": "^3.3.2" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "license": "MIT", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "license": "MIT", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..17e9daf --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "dolarito", + "version": "1.0.0", + "resourceFolder": "assets", + "wollokVersion": "4.0.0", + "author": "leo", + "license": "ISC" +}