commit 3f98422c4f3dc109866d0f8e393ec81ac9e13352 Author: thecookingsenpai Date: Mon Dec 25 13:28:22 2023 +0100 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..49945e2 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Nodepy - A library for using nodejs commands and files in Python + +## License + +This program is distributed under the terms of the CC BY-NC-SA 2.0 license + +## Installation + + wget https://github.com/thecookingsenpai/nodepy + +Now you can copy the jspyth.py file into your project directory and + + import jspyth + +And proceed to the usage as shown below + +## Usage + +### NOTE: This readme is WIP + +### NOTE: This program is in beta state + +Nodepy allows you to use nodejs commands and files in Python. + +You can either use it through: + + cmd = jspyth.JSCommand(is_file="False", command=["console.log", ["hello world"], ["eventual", "libraries", "to", "include"]], real_time=True) + result = cmd.run() + +Or with a file: + + cmd = jspyth.JSCommand(is_file="True", file="filename,js", real_time=True) + result = cmd.run() + +Where + + real_time = True/False + +Allows you to see the output in real time. + +The parameters part of the command and the include libraries are optional and should be used based on the command provided. + +## Techical informations + +The whole library is a wrapper around subthreading and is designed to be blocking, meaning that the subthread will be executed and awaited by Python. + +The only prerequisite is having node installed and to npm install the needed libraries to include. + + diff --git a/aaa.html b/aaa.html new file mode 100644 index 0000000..d27fd41 --- /dev/null +++ b/aaa.html @@ -0,0 +1,8050 @@ +Decentralized Infrastructure to Build and Earn in Web3
Ankr Token Staking is live

The fastest, most reliable Web3 infrastructure

Come see why top protocols and dApps are relying on Ankr to win Web3

7.2 Billion

Daily API requests

39,000

Distinct Developers

30+

Global regions

27

Supported Networks

Trusted by

Polygon
Binance
Optimist
AAVE
SpiritSwap
Avalanche
1inch Exchange
Project Galaxy
Zapper
SushiSwap

Your Web3 journey starts here

index.section-3.item-3.title
For Web3 Builders
index.section-3.item-3.title

The fastest multi-chain infrastructure at unbeatable pricing

Access all the developer tools you need with remote node access, advanced APIs, and the largest multi-chain network of RPCs
index.section-3.item-2.title
For Stakers

Stake and Earn with Ankr Staking products

Stake with us on Ankr.com or integrate Ankr Staking and Liquid Staking SDKs directly into your dApp.
index.section-3.item-1.title
For Game Developers

Take your Web2 game to the next level with Ankr Gaming SDKs

Integrate Web3 wallets, NFTs, and monetization tools to help turn any Web2 game into a Web3 blockbuster

Powering the Web3 Ecosystem

Ankrâs globally distributed node infrastructure allows us to
build the best possible multi-chain tools as a foundational
layer for Web3, DeFi, and the digital economy.

Building a
Multi-Chain Future

Working together in Web3 is a win-win for
everyone. Thatâs why weâre building a
more collaborative and powerful multi-
chain ecosystem.

Yin and yang showing blockchain neutrality
Chain Neutral. Providing tools to develop
and earn on all chains.
Blockchains bridging and connecting to each other
Interoperable. Connecting and bridging as
many ecosystems as possible.
A circle of decentralized blockchain nodes
Decentralized. Applying the most important
factor of Web3 to all solutions.

What are people saying?

  • Polygonâs ecosystem is greatly strengthened by Ankr, which provides premium decentralized solutions for end-users through node hosting. From instant access to the latest blocks through their developer API to providing instant liquidity for staked MATIC tokens, Ankr is paving the way for mainstream adoption. Polygon looks forward to this continued successful partnership.

    Hamzah Khan

    Head of DeFi

  • Ankr is a key infrastructure provider for the BNB Chain ecosystem â their contributions and expertise were critical in implementing upgrades to the BSC with the Erigon client, rewriting archive node infrastructure, and creating a framework for BSC Application Sidechains. This allows the BNB Chain ecosystem to remain competitive and offer both users and builders the latest benefits.

    Samy Karim

    Ecosystem Coordinator

  • Adding Ankr as an infrastructure provider helped fulfill the desires of our community members who want to build with robust and reliable services. Apps and integrations choose to build in our ecosystem because they feel aligned with our values and appreciate the breadth of tooling and technical options available to them â Ankrâs support creates yet another benefit for potential developers.

    Matthew Slipper

    Head of Engineering at OP Labs

lightning

Supercharge your project
with Ankr AppChains

Learn More
\ No newline at end of file diff --git a/jspyth.py b/jspyth.py new file mode 100644 index 0000000..4f0303e --- /dev/null +++ b/jspyth.py @@ -0,0 +1,75 @@ +import os +from subprocess import Popen, PIPE, STDOUT + +class JSCommand: + + # ANCHOR Manages the creation of a new JSCommand object + def __init__(self, is_file = False, command = [None, [], []], file="", real_time = False): + self.real_time = real_time + if is_file: + if file.strip=="": + raise Exception("File path is empty") + self.file = file + self.is_file = True + else: + if command[0]==None or command[0].strip()=="": + raise Exception("Command is empty") + self.command = command + self.is_file = False + + # ANCHOR Run management + def run(self): + if self.is_file: + self.execute_file() + else: + self.execute_cmd() + + # ANCHOR Single command execution + def execute_cmd(self): + # NOTE Command structure + # [ + # command_string, + # ["arguments", "to", "pass"], + # ["libraries", "to", "include"] + # ] + cmd_string = self.command[0] + cmd_args = self.command[1] + cmd_include = self.command[2] + temp_file = "temp.js" + temp_buffer = "" + # NOTE Include libraries + for include in cmd_include: + temp_buffer += "const " + include + " = require('" + include + "');\r\n" + temp_buffer += cmd_string + "(" + # NOTE Add arguments + for arg in cmd_args: + temp_buffer += "'" + arg + "', " + # NOTE Remove last comma if there are arguments + if len(cmd_args)>0: + temp_buffer = temp_buffer[:-2] + temp_buffer += ");" + # NOTE Write to file + with open(temp_buffer, "w+") as f: + f.write(temp_buffer) + # NOTE Execute file + self.file = temp_file + return self.execute_file() + + + # ANCHOR Whole file execution + def execute_file(self): + # NOTE Execute file + self.pid = Popen(["node", self.file], stdout=PIPE, stderr=STDOUT) + self.exec_return = "" + # NOTE Blocking execution until process is finished + while True: + line = self.pid.stdout.readline() + self.exec_return += line + "\r\n" + # NOTE Real time output if requested + if self.real_time: + print(line) + if not line: break + # NOTE Remove temp file + os.remove(self.file) + # NOTE Returns the output of the command + return self.exec_return \ No newline at end of file