Skip to content

Commit

Permalink
JS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
AtaTrkgl committed Jan 2, 2025
1 parent 2149347 commit 543a9cd
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/bundle_js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Bundle JavaScript

on:
workflow_dispatch: # Trigger on manual run
push:
branches:
- main # Trigger on push to the 'main' branch
pull_request:
branches:
- main # Trigger on pull request to 'main' branch

jobs:
bundle-js:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # Specify the Node.js version

- name: Install Dependencies
run: |
npm install terser
- name: Concatenate and Minify JavaScript
run: |
# Create a combined JS file from all *.js files in the 'js/src' directory
npx terser js/src/*.js -o js/dist/bundle.min.js --compress --mangle
- name: Commit Minified File
run: |
# Commit the minified file if it has changed
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add js/dist/bundle.min.js
git commit -m "Merged and combined JavaScript files to 'dist/bundle.min.js'"
git push
83 changes: 81 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,81 @@
# sdk

<div align="center">

![GitHub Repo stars](https://img.shields.io/github/stars/itu-helper/sdk)
![GitHub issues](https://img.shields.io/github/issues-raw/itu-helper/sdk?label=Issues&style=flat-square)

# **ITU Helper**

</div>

<div align="left">
<img src="https://raw.githubusercontent.com/itu-helper/home/main/images/logo.png" align="right"
alt="ITU Helper Logo" width="180" height="180">
</div>
<div align="center">

_İTÜ'lüler için İTÜ'lülerden_

_ITU Helper_ İstanbul Teknik Üniversitesi öğrencilerine yardım etmek amacıyla ön şart görselleştirme, ders planı oluşturma ve resmi İTÜ sitelerini birleştirme gibi hizmetler sağlayan bir açık kaynaklı websitesidir.

_ITU Helper_'a [_bu adresten_](https://itu-helper.github.io/home/) ulaşabilirsiniz.

</div>
<br>
<br>
<br>

# **itu-helper/sdk**

## **Ne İşe Yarar?**

[itu-helper/data-updater](https://github.com/itu-helper/data-updater) _repo_'suyla toplanan ve [itu-helper/data](https://github.com/itu-helper/data) _repo_'sunda saklanan verilere, kolayca ulaşılmasına olanak sağlar.

> [!NOTE]
> Verilerin nasıl isimlendirildiğine ve güncelleme sıklığına ulaşmak için, [itu-helper/data-updater](https://github.com/itu-helper/data-updater) _repo_'sununa bakınız.
## **Nasıl Kullanılır?**

### **JavaScript**

`<body>` _tag_'inin en alt kısmına şu satırı ekleyerek _script_'leri importlamanız lazım.

```html
<script src="https://cdn.jsdelivr.net/gh/itu-helper/sdk@master/js/dist/bundle.min.js"></script>
```

JavaScript SDK'sinin detaylı kullanımı için [buraya](js/README.md) bakınız.

### **HTTP Request**

Programlama dilinden bağımsız olarak, verilere _HTTP request_ göndererek de ulaşabilirsiniz. Ders planları `.txt` formatında, kalan veriler ise `.psv` (Pipe separated values) formatında saklanmakta. Aşağıdaki linklerden, dosyalara ulaşabilir ve okuyabilirsiniz.

- Dersler (_lessons_): https://raw.githubusercontent.com/itu-helper/data/main/lessons.psv

- Dersler (_courses_): https://raw.githubusercontent.com/itu-helper/data/main/courses.psv

- Ders Planları: https://raw.githubusercontent.com/itu-helper/data/main/course_plans.txt

- Bina Kodları: https://raw.githubusercontent.com/itu-helper/data/main/building_codes.psv

- Program Kodları: https://raw.githubusercontent.com/itu-helper/data/main/programme_codes.psv

#### **Python Örneği**

Aşağıdaki kodda _requests_ modülüyle; CRN kullanarak, dersin [bu sayfadaki](https://obs.itu.edu.tr/public/DersProgram) verilerine erişim gösterilmiştir.

```python
from requests import get

URL = "https://raw.githubusercontent.com/itu-helper/data/main/lessons.psv"

# Dersleri (lessons) oku ve satır satır ayır.
lines = get(URL).text.split("\n")

# .psv formatından dolayı, her bir satırdaki elementler "|" sembolü ile ayırılıyor.
# İlk eleman, dersin CRN'si. CRN'lerin "key", satırın tamamının da "value" olduğu bir sözlük oluştur.
crn_to_lesson = {line.split("|")[0] : line for line in lines}

print(crn_to_lesson["13590"])
# OUTPUT
# '13590|BLG 212E|Fiziksel (Yüz yüze)|Gökhan İnce|BBB|Monday|08:30/11:29 - |Z-18|120|111|BLG_LS, BLGE_LS, CEN_LS'
```
33 changes: 33 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div align="center">

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/itu-helper/data-updater/refresh_lessons.yml?label=Refreshing%20Lesson&logo=docusign&style=flat-square)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/itu-helper/data-updater/refresh_courses_and_plans.yml?label=Refreshing%20Courses%20%26%20Course%20Plans&logo=docusign&style=flat-square)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/itu-helper/data-updater/refresh_misc.yml?label=Refreshing%20Misc&logo=docusign&style=flat-square)
![GitHub repo size](https://img.shields.io/github/repo-size/itu-helper/data-updater?label=Repository%20Size&logo=github&style=flat-square)
![GitHub](https://img.shields.io/github/license/itu-helper/data-updater?label=License&style=flat-square)
![GitHub issues](https://img.shields.io/github/issues-raw/itu-helper/data-updater?label=Issues&style=flat-square)

# **ITU Helper**

</div>

<div align="left">
<img src="https://raw.githubusercontent.com/itu-helper/home/main/images/logo.png" align="right"
alt="ITU Helper Logo" width="180" height="180">
</div>
<div align="center">

_İTÜ'lüler için İTÜ'lülerden_

_ITU Helper_ İstanbul Teknik Üniversitesi öğrencilerine yardım etmek amacıyla ön şart görselleştirme, ders planı oluşturma ve resmi İTÜ sitelerini birleştirme gibi hizmetler sağlayan bir açık kaynaklı websitesidir.

_ITU Helper_'a [_bu adresten_](https://itu-helper.github.io/home/) ulaşabilirsiniz.

</div>
<br>
<br>
<br>

# **itu-helper/sdk - JavaScript SDK**

...
1 change: 1 addition & 0 deletions js/dist/bundle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions js/src/course.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class Course {
constructor(code, title, lang, credits, ects, requirementsText, classRestrictions, description) {
this.courseCode = code;
this.courseTitle = title;
this.lang = lang;
this.credits = credits;
this.ects = ects;
this.classRestrictions = classRestrictions;
this.description = description;

this.majorRestrictions = "";
this.lessons = [];

this._createRequirementNames(requirementsText);
}

static createAutoGeneratedCourse(code) {
return new Course(code, "Auto Generated Course", "", 0, 0, "", "", "");
}

/**
* parses the `requirementsText` and creates `this._requirementNames` array.
* @param {string} requirementsText the text written in ITU's site for requirements
*/
_createRequirementNames(requirementsText) {
// (MAT 201 MIN DDveya MAT 201E MIN DDveya MAT 210 MIN DDveya MAT 210E MIN DD)ve (EHB 211 MIN DDveya EHB 211E MIN DD)
// FIZ 102 MIN DDveya FIZ 102E MIN DDveya EHB 211 MIN DDveya EHB 211E MIN DD
this._requirementNames = [];

// If there are no requirements, return an empty list.
if (requirementsText.includes("Yok")) {
return;
}
else if (requirementsText.includes("planının") || requirementsText.includes("Diğer") || requirementsText.includes("Özel") || requirementsText.includes("için")) {
// TODO: Implement this.
return;
}

requirementsText = requirementsText
.replaceAll("veya", "\nveya")
.replaceAll("ve", "\nve")
.replaceAll("(", "")
.replaceAll(")", "");

var lines = requirementsText.split("\n");
for (let i = 0; i < lines.length; i++) {
var line = lines[i].trim();
var words = line.split(" ");

// If this is the first line, then there
// is no "ve" or "veya" in the line.
// ex: '(FIZ 101 MIN DD' ...
if (i == 0) {
this._requirementNames.push([words[0] + " " + words[1]]);
continue
}

// If the line contains "ve" or "veya".
// ex: 'veya FIZ 101E MIN DD)'
// ex2: 've (STA 201 MIN DD'
let requirementName = words[1] + " " + words[2];
let logicGate = words[0];

// Append to the last array.
if (logicGate == "veya")
this._requirementNames[this._requirementNames.length - 1].push(requirementName);
// Create a new array.
else if (logicGate == "ve")
this._requirementNames.push([requirementName]);
}
}

/**
* creates `this.requirements` array by replacing the names in `this._requirementNames`
* with the courses of the given `ITUHelper` object.
* @param {ITUHelper} ituHelper
*/
connectCourses(ituHelper) {
this.requirements = [];
for (let i = 0; i < this._requirementNames.length; i++) {
this.requirements.push([]);
for (let j = 0; j < this._requirementNames[i].length; j++) {
let course = ituHelper.findCourseByCode(this._requirementNames[i][j]);
if (course != null)
this.requirements[i].push(course);
}
}
}
}
6 changes: 6 additions & 0 deletions js/src/course_group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CourseGroup {
constructor (courses, title){
this.courses = courses;
this.title = title;
}
}
Loading

0 comments on commit 543a9cd

Please sign in to comment.