FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DailyCodingProblemScraper/utils/writeToFile.js at main · Apra487/DailyCodingProblemScraper · GitHub
Apra487
/
DailyCodingProblemScraper
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DailyCodingProblemScraper
/
utils
/
writeToFile.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (56 loc) · 1.69 KB
Breadcrumbs
DailyCodingProblemScraper
/
utils
/
writeToFile.js
Copy path
File metadata and controls
66 lines (56 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const
fs
=
require
(
'fs'
)
;
const
{
gitCommit
}
=
require
(
'./git.js'
)
;
async
function
writeToFile
(
bodyArr
)
{
// ! need to refactor this ! this is hacky solution ! Need to find a way to create the directory here
// Create a new directory named 'DailyCodingProblem'
// fs.mkdirSync('DailyCodingProblem');
// Initialize git
// const git = await gitInit();
// console.log({git});
for
(
const
i
in
bodyArr
)
{
// Create a new directory for each day
fs
.
mkdirSync
(
`DailyCodingProblem/Day
${
i
}
`
)
;
// Write the raw text to a md file
fs
.
writeFile
(
`DailyCodingProblem/Day
${
i
}
/Day
${
i
}
Problem.md`
,
bodyArr
[
i
]
.
txt
,
{
encoding
:
'utf8'
}
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
)
;
return
;
}
}
)
;
// Write it to a html file
fs
.
writeFile
(
`DailyCodingProblem/Day
${
i
}
/Day
${
i
}
Problem.html`
,
bodyArr
[
i
]
.
html
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
)
;
return
;
}
}
)
;
// Construct commit msg and commit the changes to git
await
constructCommit
(
bodyArr
[
i
]
.
txt
,
i
,
bodyArr
[
i
]
)
;
}
}
async
function
constructCommit
(
rawText
,
i
,
data
)
{
// regex to retrive 'This problem was asked by ...'
// const regex = /^This problem was[^.]*\./m;
// const match = rawText.match(regex);
// if (match) {
// const line = match[0];
// await gitCommit(`Day ${i} Problem: ${line}`);
// console.log(line);
// } else {
// console.log('No matching line found.');
// // Commit with generic message to git
// await gitCommit(`Day${i} Problem`);
// }
// Commit with generic message to git
await
gitCommit
(
data
.
subject
)
;
}
exports
.
writeToFile
=
writeToFile
;
Back
|
FazBrowse Home
|
New Git URL