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

Python 2.x removed from macOS 12.3, migrate to Java Script? #105

Open
fifafu opened this issue Jan 29, 2022 · 2 comments
Open

Python 2.x removed from macOS 12.3, migrate to Java Script? #105

fifafu opened this issue Jan 29, 2022 · 2 comments

Comments

@fifafu
Copy link
Contributor

fifafu commented Jan 29, 2022

Now that Apple has removed Python from the macOS 12.3 betas, it might make sense to switch the templates to use Java Script widgets - so no third party binaries are needed.

I'm opening this issue to discuss whether this makes sense :-)

I did a quick proof of concept script that seems to work fine, but it currently lacks any customization options apart from the coins and the currencies:

// BTT doesn't support top level await, thus needs to be wrapped in a self executing function
(async () => {
  
  const coinsToLoad = ["BTC"];
  const currenciesToLoad = ["EUR"];
  
  async function fetchCrypto(coins, currencies) {
    const fsyms = coins.join(",");
    const tsyms = currencies.join(",");
    const cryptoCompareURL = `https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${fsyms}&tsyms=${tsyms}`;
  
    const response = await fetch(cryptoCompareURL);
    const json = await response.json();
  
    const currentPrices = [];
  
    for (const currency of currencies) {
      for (const coin of coins) {
        currentPrices.push(json["RAW"][coin][currency]["PRICE"] + " " + currency);
      }
    }
  
    return currentPrices;
  }
  
  const resultPrices = await fetchCrypto(coinsToLoad, currenciesToLoad);
  
  returnToBTT(resultPrices.join(" | "));

})();

image

I will add a readFile and writeFile function to the BTT Java Script runner, so the cache can also be implemented.

@chrislennon
Copy link
Owner

chrislennon commented Jan 30, 2022

Hey, appreciate the heads up - I had no idea that had been removed. To be honest seems like a good enough reason as any to remove the python dependency.

Just to be clear the JS runs inside BTT so a user wouldn't need any nodejs installed etc?

Is there any version/limitations/spec/comparison on what's allowed inside the JS inside BTT?

@fifafu
Copy link
Contributor Author

fifafu commented Jan 30, 2022

yes it runs inside of BTT using the javascript core framework from Apple, it's available starting with 3.333 http://docs.folivora.ai/docs/1106_java_script.html

(maybe having a switch to keep python for older versions makes sense, but 3.333 was also released more than a year ago )

If we use the set_persistent_string_variable we also don't need a file based cache.

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

No branches or pull requests

2 participants