Skip to content

Commit 4cfec7c

Browse files
committed
excel somehow built it
1 parent 6289403 commit 4cfec7c

8 files changed

Lines changed: 712 additions & 89 deletions

File tree

convert/hackathon.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import XLSX from 'xlsx';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url'; // Make sure to import this
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
// Paths to the Excel and JSON files
10+
const excelFilePath = path.join(__dirname, '../excel', 'hackathons.xlsx');
11+
const jsonFilePath = path.join(__dirname, '../data', 'hackathons.json');
12+
13+
// Function to convert Excel to JSON with proper schema
14+
function convertExcelToJson() {
15+
// Read the Excel file
16+
const workbook = XLSX.readFile(excelFilePath);
17+
18+
// Assuming data is in the first sheet
19+
const sheetName = workbook.SheetNames[0];
20+
const sheet = workbook.Sheets[sheetName];
21+
22+
// Convert sheet data to JSON (object per row)
23+
const jsonData = XLSX.utils.sheet_to_json(sheet);
24+
25+
// Transform rows into schema format
26+
const hackathons = jsonData.map((row) => ({
27+
id: row["ID"] || "",
28+
title: row["Title"] || "",
29+
type: row["Type"] || "Scholarship",
30+
department: row["Department"] ? row["Department"].split(",").map((d) => d.trim()) : [],
31+
courseLevel: row["Course Level"] ? row["Course Level"].split(",").map((c) => c.trim()) : [],
32+
exclusive: row["Exclusive"] || "All",
33+
year: row["Year"] ? row["Year"].split(",").map((y) => y.trim()) : [],
34+
lastDateToApply: row["Last Date to Apply"] || "",
35+
stipend: row["Stipend"] || "",
36+
eligibility: row["Eligibility"] || "",
37+
description: row["Description"] || "",
38+
requirements: row["Requirements"] ? row["Requirements"].split(",").map((r) => r.trim()) : [],
39+
applicationLink: row["Application Link"] || "",
40+
category: row["Category"] || "",
41+
postedDate: row["Posted Date"] || ""
42+
}));
43+
44+
// Wrap into object
45+
const finalJson = { hackathons };
46+
47+
// Save JSON file
48+
fs.writeFileSync(jsonFilePath, JSON.stringify(finalJson, null, 2), 'utf-8');
49+
console.log('✅ Excel data has been converted to structured JSON!');
50+
}
51+
52+
// Run the conversion
53+
convertExcelToJson();

convert/internships.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import XLSX from 'xlsx';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url'; // Make sure to import this
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const excelFilePath = path.join(__dirname, '../excel', 'internships.xlsx');
10+
const jsonFilePath = path.join(__dirname, '../data', 'internships.json');
11+
12+
// Function to convert Excel to JSON with proper schema
13+
function convertExcelToJson() {
14+
// Read the Excel file
15+
const workbook = XLSX.readFile(excelFilePath);
16+
17+
// Assuming data is in the first sheet
18+
const sheetName = workbook.SheetNames[0];
19+
const sheet = workbook.Sheets[sheetName];
20+
21+
// Convert sheet data to JSON (object per row)
22+
const jsonData = XLSX.utils.sheet_to_json(sheet);
23+
24+
// Transform rows into schema format
25+
const internships = jsonData.map((row) => ({
26+
id: row["ID"] || "",
27+
title: row["Title"] || "",
28+
type: row["Type"] || "Scholarship",
29+
department: row["Department"] ? row["Department"].split(",").map((d) => d.trim()) : [],
30+
courseLevel: row["Course Level"] ? row["Course Level"].split(",").map((c) => c.trim()) : [],
31+
exclusive: row["Exclusive"] || "All",
32+
year: row["Year"] ? row["Year"].split(",").map((y) => y.trim()) : [],
33+
lastDateToApply: row["Last Date to Apply"] || "",
34+
stipend: row["Stipend"] || "",
35+
eligibility: row["Eligibility"] || "",
36+
description: row["Description"] || "",
37+
requirements: row["Requirements"] ? row["Requirements"].split(",").map((r) => r.trim()) : [],
38+
applicationLink: row["Application Link"] || "",
39+
category: row["Category"] || "",
40+
postedDate: row["Posted Date"] || ""
41+
}));
42+
43+
// Wrap into object
44+
const finalJson = { internships };
45+
46+
// Save JSON file
47+
fs.writeFileSync(jsonFilePath, JSON.stringify(finalJson, null, 2), 'utf-8');
48+
console.log('✅ Excel data has been converted to structured JSON!');
49+
}
50+
51+
// Run the conversion
52+
convertExcelToJson();

convert/others.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import XLSX from 'xlsx';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url'; // Make sure to import this
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
// Paths to the Excel and JSON files
9+
const excelFilePath = path.join(__dirname, '../excel', 'others.xlsx');
10+
const jsonFilePath = path.join(__dirname, '../data', 'others.json');
11+
12+
// Function to convert Excel to JSON with proper schema
13+
function convertExcelToJson() {
14+
// Read the Excel file
15+
const workbook = XLSX.readFile(excelFilePath);
16+
17+
// Assuming data is in the first sheet
18+
const sheetName = workbook.SheetNames[0];
19+
const sheet = workbook.Sheets[sheetName];
20+
21+
// Convert sheet data to JSON (object per row)
22+
const jsonData = XLSX.utils.sheet_to_json(sheet);
23+
24+
// Transform rows into schema format
25+
const others = jsonData.map((row) => ({
26+
id: row["ID"] || "",
27+
title: row["Title"] || "",
28+
type: row["Type"] || "Scholarship",
29+
department: row["Department"] ? row["Department"].split(",").map((d) => d.trim()) : [],
30+
courseLevel: row["Course Level"] ? row["Course Level"].split(",").map((c) => c.trim()) : [],
31+
exclusive: row["Exclusive"] || "All",
32+
year: row["Year"] ? row["Year"].split(",").map((y) => y.trim()) : [],
33+
lastDateToApply: row["Last Date to Apply"] || "",
34+
stipend: row["Stipend"] || "",
35+
eligibility: row["Eligibility"] || "",
36+
description: row["Description"] || "",
37+
requirements: row["Requirements"] ? row["Requirements"].split(",").map((r) => r.trim()) : [],
38+
applicationLink: row["Application Link"] || "",
39+
category: row["Category"] || "",
40+
postedDate: row["Posted Date"] || ""
41+
}));
42+
43+
// Wrap into object
44+
const finalJson = { others };
45+
46+
// Save JSON file
47+
fs.writeFileSync(jsonFilePath, JSON.stringify(finalJson, null, 2), 'utf-8');
48+
console.log('✅ Excel data has been converted to structured JSON!');
49+
}
50+
51+
// Run the conversion
52+
convertExcelToJson();

convert/research.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import XLSX from 'xlsx';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url'; // Make sure to import this
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
// Paths to the Excel and JSON files
10+
const excelFilePath = path.join(__dirname, '../excel', 'research.xlsx');
11+
const jsonFilePath = path.join(__dirname, '../data', 'research.json');
12+
13+
// Function to convert Excel to JSON with proper schema
14+
function convertExcelToJson() {
15+
// Read the Excel file
16+
const workbook = XLSX.readFile(excelFilePath);
17+
18+
// Assuming data is in the first sheet
19+
const sheetName = workbook.SheetNames[0];
20+
const sheet = workbook.Sheets[sheetName];
21+
22+
// Convert sheet data to JSON (object per row)
23+
const jsonData = XLSX.utils.sheet_to_json(sheet);
24+
25+
// Transform rows into schema format
26+
const research = jsonData.map((row) => ({
27+
id: row["ID"] || "",
28+
title: row["Title"] || "",
29+
type: row["Type"] || "Scholarship",
30+
department: row["Department"] ? row["Department"].split(",").map((d) => d.trim()) : [],
31+
courseLevel: row["Course Level"] ? row["Course Level"].split(",").map((c) => c.trim()) : [],
32+
exclusive: row["Exclusive"] || "All",
33+
year: row["Year"] ? row["Year"].split(",").map((y) => y.trim()) : [],
34+
lastDateToApply: row["Last Date to Apply"] || "",
35+
stipend: row["Stipend"] || "",
36+
eligibility: row["Eligibility"] || "",
37+
description: row["Description"] || "",
38+
requirements: row["Requirements"] ? row["Requirements"].split(",").map((r) => r.trim()) : [],
39+
applicationLink: row["Application Link"] || "",
40+
category: row["Category"] || "",
41+
postedDate: row["Posted Date"] || ""
42+
}));
43+
44+
// Wrap into object
45+
const finalJson = { research };
46+
47+
// Save JSON file
48+
fs.writeFileSync(jsonFilePath, JSON.stringify(finalJson, null, 2), 'utf-8');
49+
console.log('✅ Excel data has been converted to structured JSON!');
50+
}
51+
52+
// Run the conversion
53+
convertExcelToJson();

convert/scholarships.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import XLSX from 'xlsx';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
// Paths to the Excel and JSON files
10+
const excelFilePath = path.join(__dirname, '../excel', 'scholarships.xlsx');
11+
const jsonFilePath = path.join(__dirname, '../data', 'scholarships.json');
12+
13+
// Function to convert Excel to JSON with proper schema
14+
function convertExcelToJson() {
15+
// Read the Excel file
16+
const workbook = XLSX.readFile(excelFilePath);
17+
18+
// Assuming data is in the first sheet
19+
const sheetName = workbook.SheetNames[0];
20+
const sheet = workbook.Sheets[sheetName];
21+
22+
// Convert sheet data to JSON (object per row)
23+
const jsonData = XLSX.utils.sheet_to_json(sheet);
24+
25+
// Transform rows into schema format
26+
const scholarships = jsonData.map((row) => ({
27+
id: row["ID"] || "",
28+
title: row["Title"] || "",
29+
type: row["Type"] || "Scholarship",
30+
department: row["Department"] ? row["Department"].split(",").map((d) => d.trim()) : [],
31+
courseLevel: row["Course Level"] ? row["Course Level"].split(",").map((c) => c.trim()) : [],
32+
exclusive: row["Exclusive"] || "All",
33+
year: row["Year"] ? row["Year"].split(",").map((y) => y.trim()) : [],
34+
lastDateToApply: row["Last Date to Apply"] || "",
35+
stipend: row["Stipend"] || "",
36+
eligibility: row["Eligibility"] || "",
37+
description: row["Description"] || "",
38+
requirements: row["Requirements"] ? row["Requirements"].split(",").map((r) => r.trim()) : [],
39+
applicationLink: row["Application Link"] || "",
40+
category: row["Category"] || "",
41+
postedDate: row["Posted Date"] || ""
42+
}));
43+
44+
// Wrap into object
45+
const finalJson = { scholarships };
46+
47+
// Save JSON file
48+
fs.writeFileSync(jsonFilePath, JSON.stringify(finalJson, null, 2), 'utf-8');
49+
console.log('✅ Excel data has been converted to structured JSON!');
50+
}
51+
52+
// Run the conversion
53+
convertExcelToJson();

0 commit comments

Comments
 (0)