File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed
Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change 1- import * as py from 'rustpython_wasm' ;
1+ import * as rp from 'rustpython_wasm' ;
22import pyCode from 'raw-loader!./main.py' ;
33
4- fetch ( 'https://github-trending-api.now.sh/repositories' )
5- . then ( r => r . json ( ) )
6- . then ( repos => {
7- const result = py . pyEval ( pyCode , {
8- vars : { repos }
9- } ) ;
10- alert ( result ) ;
11- } ) ;
4+ const vm = rp . vmStore . get ( 'main' ) ;
5+
6+ vm . exec ( pyCode ) ;
Original file line number Diff line number Diff line change 1- repos = js_vars [ 'repos' ]
1+ from browser import fetch
22
3- star_sum = 0
3+ def fetch_handler (repos ):
4+ star_sum = 0
5+ for repo in repos :
6+ star_sum += repo ['stars' ]
7+ print (f'Average github trending star count: { star_sum / len (repos )} ' )
48
5- for repo in repos :
6- star_sum += repo ['stars' ]
79
8- return 'Average github trending star count: ' + str (star_sum / len (repos ))
10+ fetch (
11+ 'https://github-trending-api.now.sh/repositories' ,
12+ response_format = 'json' ,
13+ ).then (fetch_handler )
You can’t perform that action at this time.
0 commit comments