Skip to content

Instantly share code, notes, and snippets.

@movahhedi
Created April 10, 2024 16:59
Show Gist options
  • Save movahhedi/871932a942b08eddc1c389f33fc06af3 to your computer and use it in GitHub Desktop.
Save movahhedi/871932a942b08eddc1c389f33fc06af3 to your computer and use it in GitHub Desktop.
Exporting subjects from IAU's Amoozeshyar. Run it in the browser console.
const trs = document.querySelectorAll("#tableContainer tbody tr");
const dataColumnsRaw = [];
const dataArrayRaw = [];
const ths = document.querySelectorAll("#tableContainer thead tr th");
ths.forEach((th) => {
dataColumnsRaw.push(th.textContent?.trim());
});
trs.forEach((tr) => {
const tds = tr.querySelectorAll("td");
const trData = [];
tds.forEach((td) => {
trData.push(td.textContent?.trim());
});
dataArrayRaw.push(trData);
});
/* const importantColumns = [2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 16, 17, 18, 19, 20];
const dataColumns = dataColumnsRaw.filter((value, index) => {
return importantColumns.includes(index);
});
const dataArray = dataArrayRaw.map((i) =>
i.filter((value, index) => {
return importantColumns.includes(index);
})
); */
const dataColumns = dataColumnsRaw;
const dataArray = dataArrayRaw;
const data = dataArray.map((value, index, array) => {
const a = {};
dataColumns.forEach((columnName, columnIndex) => {
a[columnName] = value[columnIndex];
});
return a;
});
data.sort((a, b) => {
const keyName = "نام درس";
return a[keyName] < b[keyName] ? -1 : a[keyName] > b[keyName] ? 1 : 0;
});
data.sort((a, b) => {
const sortKeys = ["استان", "واحد", "دانشکده", "گروه آموزشی", "نام درس", "استاد", "زمانبندي تشکيل کلاس"];
let result = false;
sortKeys.forEach((key) => {
result = result || a[key].localeCompare(b[key]);
})
// return a[sortKeys[0]].localeCompare(b[sortKeys[0]]) || a[sortKeys[1]].localeCompare(b[sortKeys[1]]) || a[sortKeys[2]].localeCompare(b[sortKeys[2]]);
return result;
});
const dataSorted = data.map((i) => {
// Create an object which will serve as the order template
const objectOrder = {
"كد درس": null,
"نام درس": null,
"استاد": null,
"زمانبندي تشکيل کلاس": null,
"نام كلاس درس": null,
"زمان امتحان": null,
"كد ارائه کلاس درس": null,
};
return Object.assign(objectOrder, i);
});
const json = JSON.stringify(dataSorted);
console.log(json);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment