1010 let path = require ( 'path' ) ;
1111
1212 const data = require ( './impl/data' ) ;
13+ const db = require ( './impl/db' ) ;
1314 const DbFile = require ( './impl/dbFile' ) ;
1415 const fetchJson = require ( './impl/fetchJson' ) ;
1516 const github = require ( './impl/github' ) ;
@@ -67,34 +68,21 @@ optional arguments:
6768 }
6869
6970 if ( cli . input . length === 1 ) {
70- await fetchUserDetailsAndContribs ( `${ cli . input [ 0 ] . toLowerCase ( ) } .json` ) ;
71+ const userFilePath = path . join ( data . users , `${ cli . input [ 0 ] . toLowerCase ( ) } .json` ) ;
72+ const user = new DbFile ( userFilePath ) ;
73+ await fetchUserDetailsAndContribs ( user ) ; //LA_TODO to be tested
7174 } else {
72- for ( const file of fs . readdirSync ( data . users ) ) {
73- if ( file . endsWith ( '.json' ) ) {
74- await fetchUserDetailsAndContribs ( file ) ;
75- }
75+ for await ( const user of db . asyncNonRemovedUsers ( ) ) {
76+ await fetchUserDetailsAndContribs ( user ) ; //LA_TODO to be tested
7677 }
7778 }
7879
7980 return ;
8081
81- async function fetchUserDetailsAndContribs ( userFileName ) {
82- let spinner ;
83-
84- const userFilePath = path . join ( data . users , userFileName ) ;
85- const userFile = new DbFile ( userFilePath ) ;
82+ async function fetchUserDetailsAndContribs ( userFile ) {
8683 if ( ! userFile . login ) {
8784 throw `${ userFilePath } is malformed. Did you run ./addUser.js ?` ;
8885 }
89- if ( userFile . ghuser_deleted_because ) {
90- console . log ( `${ userFile . login } has been deleted, skipping...` ) ;
91- return ;
92- }
93- if ( userFile . removed_from_github ) {
94- // For now ok, but maybe some day we'll have to deal with resurrected users.
95- console . log ( `${ userFile . login } was removed from GitHub in the past, skipping...` ) ;
96- return ;
97- }
9886
9987 {
10088 const now = new Date ;
@@ -117,7 +105,7 @@ optional arguments:
117105
118106 async function fetchDetails ( userFile ) {
119107 const ghUserUrl = `https://api.github.com/users/${ userFile . login } ` ;
120- spinner = ora ( `Fetching ${ ghUserUrl } ...` ) . start ( ) ;
108+ const spinner = ora ( `Fetching ${ ghUserUrl } ...` ) . start ( ) ;
121109 const ghDataJson = await github . fetchGHJson (
122110 ghUserUrl , spinner , [ 304 , 404 ] ,
123111 userFile . contribs && userFile . contribs . fetched_at && new Date ( userFile . contribs . fetched_at )
@@ -151,7 +139,7 @@ optional arguments:
151139
152140 async function fetchOrgs ( userFile ) {
153141 const orgsUrl = userFile . organizations_url ;
154- spinner = ora ( `Fetching ${ orgsUrl } ...` ) . start ( ) ;
142+ const spinner = ora ( `Fetching ${ orgsUrl } ...` ) . start ( ) ;
155143 const orgsDataJson = await github . fetchGHJson ( orgsUrl , spinner ) ;
156144 spinner . succeed ( `Fetched ${ orgsUrl } ` ) ;
157145
@@ -194,7 +182,7 @@ optional arguments:
194182 // fetchUserContribs() won't find forks as they are not considered to be contributions. But
195183 // the user might well have popular forks.
196184
197- spinner = ora ( `Fetching ${ userFile . login } 's popular forks...` ) . start ( ) ;
185+ const spinner = ora ( `Fetching ${ userFile . login } 's popular forks...` ) . start ( ) ;
198186
199187 const perPage = 100 ;
200188 for ( let page = 1 ; page <= 5 ; ++ page ) {
@@ -219,7 +207,7 @@ optional arguments:
219207
220208 async function fetchSettings ( userFile ) {
221209 const url = `https://raw.githubusercontent.com/${ userFile . login } /ghuser.io.settings/master/ghuser.io.json` ;
222- spinner = ora ( `Fetching ${ userFile . login } 's settings...` ) . start ( ) ;
210+ const spinner = ora ( `Fetching ${ userFile . login } 's settings...` ) . start ( ) ;
223211
224212 const dataJson = await fetchJson ( url , spinner , [ 404 ] ) ;
225213 if ( dataJson == 404 ) {
0 commit comments