{"id":21305233,"url":"https://github.com/maragedev/jstopy","last_synced_at":"2025-10-24T10:32:26.920Z","repository":{"id":155615921,"uuid":"505639438","full_name":"MarageDev/JsToPy","owner":"MarageDev","description":"A simple method to create events from a JavaScript file, receive them in the Python file and then retrieve them in the JavaScript file","archived":false,"fork":false,"pushed_at":"2022-06-21T11:30:19.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-12T01:28:44.899Z","etag":null,"topics":["interaction","javascript","python","subprocess"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarageDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-21T00:33:16.000Z","updated_at":"2022-06-21T14:04:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8ad2b1e-48ac-4100-85b8-48cb6cf90c94","html_url":"https://github.com/MarageDev/JsToPy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MarageDev/JsToPy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarageDev%2FJsToPy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarageDev%2FJsToPy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarageDev%2FJsToPy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarageDev%2FJsToPy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarageDev","download_url":"https://codeload.github.com/MarageDev/JsToPy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarageDev%2FJsToPy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280782961,"owners_count":26390267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interaction","javascript","python","subprocess"],"created_at":"2024-11-21T16:17:20.965Z","updated_at":"2025-10-24T10:32:26.893Z","avatar_url":"https://github.com/MarageDev.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003e JsToPy \u003c/h2\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://discord.gg/8T2Ba2V2hj\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/DISCORD-Link-5662f6.svg?style=for-the-badge\u0026logo=discord\" alt=\"Discord Link\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"#\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/GITHUB-Marage Dev-blue?style=for-the-badge\u0026logo=github\" alt=\"Github Profile\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003ch3 align=\"center\"\u003eA simple method to create events from a JavaScript file and receive them in the Python file\u003c/h3\u003e\n\u003ch6 align=\"center\"\u003e  Normally there's no need to modify but if you've found a way to improve it or a fix to an error, let me know \u003c/h6\u003e\n\n\n\n## What is it ?\nThis is a simple method to create events from a JavaScript file, receive them in the Python file and then retrieve them in the JavaScript file\n### How to download the files\nTo download the files you can clone the repository or download the .zip folder.\n### How to run the program\n  To run the program, open a terminal and type. Change `index.js` by the name of your JavaScript file if you changed it.\n ```\n node index.js\n ```\n### The Result\nIn the terminal, you will see different logs which are the functions I already added as a demonstration. If everything is working fine, you should see\n```\nData received from python : Arguments associated with this event -\u003e Magic Note This is the event named :  CreateNewCustomFile\n\nData received from python : lorem ipsum abracadabra Meeska Moska Mickey Mouse 21\n```\n These are the 2 events from `index.js` with their corresponding functions in Python in `main.py`. The first one creates a new `.txt` file with a name based on the first of the arguments of the event, and 2 other ones for the content : \n- argument 1 -\u003e \"Magic Note\" ( the name of the file to create )\n- argument 2 -\u003e \"This is the event named : \" ( first of the 2 strings composing the text file )\n- argument 3 -\u003e \"CreateNewCustomFile\" ( the last of the 2 strings composing the text file )\n\nAnd the second one returns a log with the differents arguments from the event inside : \n- argument 1 -\u003e \"Meeska Moska Mickey Mouse\"\n- argument 2 -\u003e \"50\" ( which is a value determining the maximal range of the random integer )\n\n## Documentation\nThe part below will describe how to use the code\n\n### JavaScript part\nThis is the part of the program in `index.js`, you can find the whole code in the file aswell as the comments\n\nThe function in the file `index.js` named `sendEvent` handle the events of the program.\n\u003e Normally there's no need to modify but if you've found a way to improve it or a fix to an error, let me know\n```js\nfunction sendEvent (name, args){\n    // Define the array and add the default values\n    spawnerArgs = ['./main.py', `${name}`]\n\n    // Check if the event contains arguments\n    if(typeof args  !== 'undefined' ){\n        // Add every arguments to the array \"spawnerArgs\"\n        args.forEach(element =\u003e {\n            spawnerArgs.push(element)\n        });\n    }else{\n        // If it doesn't contain any arguments, do nothing\n        console.log(\"Doesn't possess args\")\n    }\n\n    // Add the event and its arguments from \"spawnerArgs\" and the receive part\n    python_process = spawner('python', spawnerArgs)\n    python_process.stdout.on('data', (data) =\u003e {\n        console.log('Data received from python :', data.toString())\n    })\n}\n```\n\nThen, you can send events in from the JavaScript file using the method\n\u003e Don't forget to put the arguments inside of an array. You can add more than 2 arguments by adding a coma and entering the name of the next argument\n```js\nsendEvent('STRING - EVENT NAME', ['STRING - ARGUMENT 1','STRING - ARGUMENT 2'])\n```\n\n### Python part\nThis part is for the code in `main.py`\n\nThis is the most important part of the python file. The variable `event` receives the event from the JavaScript file and gets its second argument ( this is a part of `index.js` )\n```js\n['./main.py', 'STRING - EVENT NAME']\n              ^^^^\n```\nThen, the array `args` will save the arguments of the event, it'll save only after the second element ( another reference to `index.js`, this part has been automatized )\n```js\nsendEvent('STRING - EVENT NAME',  ['STRING - ARGUMENT 1', 'STRING - ARGUMENT 2'])\n                                  ^^^^                    ^^^^\npython_process = spawner('python', './main.py', 'STRING - EVENT NAME',  [ 'STRING - ARGUMENT 1',  'STRING - ARGUMENT 2'])\n                                                                          ^^^^                    ^^^^\n```\n```py\n# Import sys\nimport sys\n\n# Define the name of the event, it's the second argument\nevent = sys.argv[1]\n# Define every arguments after the name of the event in an array\nargs = sys.argv[2:]\n```\n\nTo add the python code of the events, you can create a function corresponding to the event and add it the number of arguments you registered previously in `index.js`\n```js\nsendEvent('CreateNewCustomFile', ['Magic Note','This is the event named : ','CreateNewCustomFile'])\n```\nand add in the Python code in `main.py`\n```py\ndef CreateFile(fileName, stSentece, ndSentence):\n    with open(f'{fileName}.txt', 'w') as f:\n        f.write(f'{stSentece} {ndSentence}')\n    return print(f'Arguments associated with this event -\u003e {args[0]} {args[1]} {args[2]}') \n```\nThen this function will be triggered by this part in `main.py`, you can add the arguments of the event here\n```py\nif event == 'CreateNewCustomFile':\n    output = CreateFile(args[0],args[1],args[2])\n```\n\n## Credits\nMarage\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaragedev%2Fjstopy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaragedev%2Fjstopy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaragedev%2Fjstopy/lists"}