mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Update WASM example crate/app
This commit is contained in:
2 files changed
+14
-14
No files matched your search
@@ -1,11 +1,6 @@
|
||||
import * as py from 'rustpython_wasm';
|
||||
import * as rp from 'rustpython_wasm';
|
||||
import pyCode from 'raw-loader!./main.py';
|
||||
|
||||
fetch('https://github-trending-api.now.sh/repositories')
|
||||
.then(r => r.json())
|
||||
.then(repos => {
|
||||
const result = py.pyEval(pyCode, {
|
||||
vars: { repos }
|
||||
});
|
||||
alert(result);
|
||||
});
|
||||
const vm = rp.vmStore.get('main');
|
||||
|
||||
vm.exec(pyCode);
|
||||
@@ -1,8 +1,13 @@
|
||||
repos = js_vars['repos']
|
||||
from browser import fetch
|
||||
|
||||
star_sum = 0
|
||||
def fetch_handler(repos):
|
||||
star_sum = 0
|
||||
for repo in repos:
|
||||
star_sum += repo['stars']
|
||||
print(f'Average github trending star count: {star_sum / len(repos)}')
|
||||
|
||||
for repo in repos:
|
||||
star_sum += repo['stars']
|
||||
|
||||
return 'Average github trending star count: ' + str(star_sum / len(repos))
|
||||
fetch(
|
||||
'https://github-trending-api.now.sh/repositories',
|
||||
response_format='json',
|
||||
).then(fetch_handler)
|
||||
Reference in new issue
Block a user