Skip to content

Commit 939008f

Browse files
committed
u
1 parent f651a34 commit 939008f

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require("fs");
2+
3+
// Read the input file
4+
fs.readFile("input.txt", "utf8", (err, data) => {
5+
if (err) {
6+
console.error(err);
7+
return;
8+
}
9+
10+
// Join lines with "#"
11+
let joined = data.replace(/\r?\n/g, "#");
12+
13+
// Replace "**" with newline
14+
let result = joined.replace(/\*\*/g, "\n");
15+
16+
// Write the result to output.txt
17+
fs.writeFile("output.txt", result, "utf8", (err) => {
18+
if (err) {
19+
console.error(err);
20+
return;
21+
}
22+
console.log("Output saved to output.txt");
23+
});
24+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const fs = require("fs");
2+
3+
// Read the JSON file
4+
fs.readFile("addfootnotes.json", "utf8", (err, data) => {
5+
if (err) {
6+
console.error(err);
7+
return;
8+
}
9+
10+
let jsonData = JSON.parse(data);
11+
12+
// Read the footnotes file
13+
fs.readFile("footnotes.txt", "utf8", (err, footnotesData) => {
14+
if (err) {
15+
console.error(err);
16+
return;
17+
}
18+
19+
let footnotes = footnotesData.match(/\[\d+\][^\[\]]+/g);
20+
21+
// Process the data
22+
for (let i = 0; i < jsonData.length; i++) {
23+
let matches = jsonData[i][0].match(/\[\d+\]/g);
24+
if (matches) {
25+
for (let j = 0; j < matches.length; j++) {
26+
let match = matches[j];
27+
let index = footnotes.findIndex((fn) => fn.startsWith(match));
28+
if (index !== -1) {
29+
let footnoteNumber = match.substring(1, match.length - 1);
30+
let footnoteText = footnotes[index].replace(match, "").trim();
31+
if (jsonData[i][1]) {
32+
jsonData[i][1] += "\n[" + footnoteNumber + "] " + footnoteText;
33+
} else {
34+
jsonData[i][1] = "[" + footnoteNumber + "] " + footnoteText;
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
// Write the output JSON file
42+
fs.writeFile("output.json", JSON.stringify(jsonData, null, 2), (err) => {
43+
if (err) {
44+
console.error(err);
45+
return;
46+
}
47+
console.log("Output JSON file has been created successfully.");
48+
});
49+
});
50+
});

notes/scripts/for work/dfk/readme.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
place ** where new rows are supposed to start in the word file.
2+
3+
save word file as plain txt, unicode utf 8.
4+
5+
open in google sheets, remove columns after first column, check if they have text first
6+
7+
download as excel file, find and select, go to special, blanks. then in "cells" menu, click delete. save as plain text called input
8+
9+
...
10+
11+
i have text file that looks somewhat like this:
12+
13+
ދަންނާށެވެ! އިސްލާމްދީނަކީ ސުންނަތެވެ. އަދި ސުންނަތަކީ އިސްލާމްދީނެވެ. އެއިން އެއްކަމެއްވެސް އަނެއްކަމާއި ލައިގެން މެނުވީ ޤާއިމްނުވާހުއްޓެވެ.[5]
14+
**
15+
ފަހެ ސުންނަތުގެ ތެރޭގައި: ޖަމާޢަތުގައި ލާޒިމްވެހުރުން ހިމެނެއެވެ. ޖަމާޢަތް ފިޔަވައި އެހެން އެއްޗަކަށް އެދުންވެރިވެ އެޖަމާޢަތާއި ވަކިވެގަނެއްޖެމީހާ ފަހެ އިސްލާމްކަމުގެ އުޅައްގަނޑު އޭނާގެ ކަރުން މަހާ އެއްލާލައިފިއެވެ. އަދި އޭނާ ވާހުށީ މަގުފުރެދިގެންވާ މަގުފުރައްދަނިވި މީހެއްކަމުގައިއެވެ.[6]**
16+
އަދި އެކަމެއްގެ މަތީގައި ޖަމާޢަތް ބިނާވެގެންވާ އަސާސަކީ އަދި އެޖަމާޢަތަކީ: މުޙައްމަދު صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ ގެ އަޞްޙާބުންނެވެ. -އެހުރިހާ ބޭކަލުންނަށް އެކަލާނގެ ރަޙްމަތްލައްވާށިއެވެ- އަދި އެބޭކަލުންނީ އަހުލުއްސުންނާ ވަލްޖަމާޢަތެވެ. ފަހެ އެބޭކަލުންގެ އަރިހުން (ހިދާޔަތާއި މަގު) ނުނަގާ މީހާ، ހަމަކަށަވަރުންވެސް މަގުފުރެދިގަނެ ބިދުޢަ ހަދައިފިއެވެ. އަދި ކޮންމެ ބިދުޢައަކީ މަގުފުރެދުމެކެވެ. އަދި ކޮންމެ މަގުފުރެދުމަކާއި އޭގެ އަހުލުވެރިންވަނީ ނަރަކާގައިއެވެ.[7]
17+
18+
...
19+
20+
every new line should join the line before and after that, with a "#" in between them
21+
22+
after that is done, every "**" should be replaced with a new line
23+
24+
input file is called "input.txt"
25+
26+
output file should be called "output.txt"
27+
28+
do it in js
29+
30+
...
31+
32+
33+
open output text in excel. check if any data is in another column. if that data is from footnote, it doesnt matter.
34+
35+
copy plain paste the first column onto google sheets.
36+
37+
download as csv, convert to json via papaparse.
38+
39+
open json in vscode, replace "#" with "\n" (make sure regex is off)
40+
41+
convert to csv
42+
https://www.convertcsv.com/json-to-csv.htm
43+
dont include header in first row
44+
45+
import to google sheets
46+
data cleaup, trim whitespace
47+
48+
regular copy paste (not plain paste) column over to final db table sheet
49+
50+
check whether a row is missing, and fix. maybe you forgot to put a ** somewhere
51+
52+
everything should fit. as for the last row, it will contain footnotes, and maybe fihristh if that was present
53+
54+
...
55+
56+
as for footnotes, you can find them in the initial plain text file we made
57+
58+
look for "[1]" to know where it begins
59+
60+
copy that text over to a new text file called footnotes.txt
61+
62+
replace "\n" with "#"
63+
64+
...
65+
66+
i have a json file 2d array file called "addfootnotes.json"
67+
68+
it looks somewhat like this:
69+
70+
[
71+
"އަދި (ސުންނަތުގެ ތެރޭގައި) ޤިޔާމަތްދުވަހު ﷲ ތަޢާލާ ފެންނާނޭކަމަށް އީމާންވުންވެއެވެ. (މުއުމިނުން)ގެ ބޯތަކުގައިވާ ލޯތަކުން ސީދާ އެކަލާނގެ ފެންނަހުއްޓެވެ. އަދި އެއްވެސް ފަރްދާއެއް ތަރްޖަމާނެއްނެތި އެކަލާނގެ އެބައިމީހުންގެ ޙިސާބު ބައްލަވާނެތެވެ.[23]",
72+
"column2 row1 data"
73+
],
74+
[
75+
"އަދި ޤިޔާމަތްދުވަހުގައިވާ ތިލަފަތަށް އީމާންވުމެވެ. އެތިލަފަތުގައި ހެޔޮކަންތަކާއި ނުބައިކަންތައް މިނެކިރޭހުއްޓެވެ. އެތިލަފަތަށް ދެކިބައާއި މެދުދަނޑި ލިބިގެންވެއެވެ.[24]",
76+
""
77+
],
78+
[
79+
"އަދި ޤަބުރުގެ ޢަޛާބާއި މުންކަރުއާއި ނަކީރު ދެމަލާއިކަތުންނަށް އީމާންވުންވެއެވެ.[25]",
80+
""
81+
],
82+
83+
i also have a txt file called "footnotes.txt"
84+
85+
it has data similar to the following:
86+
87+
[1] تاريخ بغداد: 13/534 [2] البداية والنهاية: 11/227 [3] طبقات الحنابلة: 2/44-45، المنتظم: 14/14 [4] المنتظم: 14/15
88+
89+
now what i want you to do is, using js, check the first row of the first column in addfootnotes.json, if it has a number like so "[4]" then look for that same number within the same brackets in the footnotes.txt, and copy all the text (from that number in the footnotes.txt to right before start of the next such number in footnotes.txt) to the second column of the corresponding row in addfootnotes.json.
90+
91+
note that a row in the first column can have multiple such numbers. in which case, copy over the first instance of that number and its text from footnotes.txt, and after that, copy the next such number to the same row in the second column, but after the previous copied over number, seperating them with a new line
92+
93+
output should be called "output.json"
94+
95+
...
96+
97+
that does copy over the text into the second column, but not the number
98+
99+
the output i am getting is:
100+
101+
[
102+
"ޢީސާ ބްނު މަރްޔަމް عَلَيْهَا السَّلَام ފައިބާވަޑައިގެންފުމަށް ދާންދެން ޚިލާފަތްވަނީ ޤުރައިޝުވަންހައިގެ ތެރޭގައިއެވެ.[41]",
103+
"ހުރިހާ މުސްލިމުން ކިޔަމަންވާ އެއް ވެރިޔަކުކަމުގައި ޚަލީފާއެއް ކަނޑައެޅުމަކީ ބޮޑުވެގެންވާ ވާޖިބެކެވެ. އަދި އެއްޒަމާނެއްގައި ދެޚަލީފާއިން ތިބުން ހުއްދަވެގެން",
104+
]
105+
106+
when i should be getting:
107+
108+
[
109+
"ޢީސާ ބްނު މަރްޔަމް عَلَيْهَا السَّلَام ފައިބާވަޑައިގެންފުމަށް ދާންދެން ޚިލާފަތްވަނީ ޤުރައިޝުވަންހައިގެ ތެރޭގައިއެވެ.[41]",
110+
"[41] ހުރިހާ މުސްލިމުން ކިޔަމަންވާ އެއް ވެރިޔަކުކަމުގައި ޚަލީފާއެއް ކަނޑައެޅުމަކީ ބޮޑުވެގެންވާ ވާޖިބެކެވެ. އަދި އެއްޒަމާނެއްގައި ދެޚަލީފާއިން ތިބުން ހުއްދަވެގެން",
111+
]
112+
113+
...
114+
115+
remove the
116+
117+
column2 row1 data
118+
it might exist in more than 1 place
119+
120+
at the beginning
121+
122+
convert json to csv
123+
dont include header in first row
124+
125+
import to google sheets
126+
127+
128+

0 commit comments

Comments
 (0)