siamauth

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 8 Imported by: 0

README

SIAM UB Auth

https://siam.ub.ac.id authentication with scraping method. +scraping some other data like krs, addcourse, etc

import:

import (
	"github.com/dnabil/siamauth"
)

run go get command:

go get -u github.com/dnabil/siamauth

What's New

Breaking Changes (v0.3.0):

  • Login function now returns 2 data, error msg (string) and error

New:

  • feat: user.GetDataAndLogout, basically: Login() GetData() and Logout()
  • feat: user.GetKrs & ScrapeKrs (/krs.php)
  • feat: ScrapeAddCourse logic (/addcourse.php)
  • the go-colly collector is now public in user's field (user.C)
  • more stable & efficient (added some tests and fixed some bad logic)

Usage

siamauth constructor

user := siamauth.NewUser()

After that you can use the methods available for that user :D (use user.Login() first pls n then u can start web scraping siam). Documentation or see this code example.

Please note that after logging in, please defer user.Logout() so the session id won't be misused.

Or if you just need the scraping logic for scraping siam pages (if you have the html pages), use the funcs that starts with Scrape.. like ScrapeAddCourse to scrape /addcourse.php data, etc. Just pass in the html page as io.Reader as the argument.

Pull requests are welcome :)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// not logged in err
	ErrNotLoggedIn error = errors.New("please login first")
	// logged in err, y u try to log back in
	ErrLoggedIn error = errors.New("already logged in")
	// caused by siam UI changes/passed in the wrong page
	ErrNoElement error = errors.New("element not found")
	// login fail
	ErrLoginFail error = errors.New("login fail, wrong credentials?")
)

Functions

func ScrapeLoginError added in v0.3.0

func ScrapeLoginError(r io.Reader) (string, error)

page: login

will return error login message as string and an error

error may be caused by: html parse error, siam UI changes

Types

type AddCourse added in v0.3.0

type AddCourse struct {
	MasaKRS string

	Hari           string // Nama hari
	Jam            string // HH:MM - HH:MM
	Kelas          string
	ProgramStudi   string
	Kode           string
	MataKuliah     string
	TahunKurikulum string // YEAR
	Peminat        int    // [PEMINAT]/[kuota]
	Kuota          int    // [peminat]/[KUOTA]
	SKS            int
	Ruang          string
	Jenis          string // Luring/Daring/Hybrid
}

func ScrapeAddCourse added in v0.3.0

func ScrapeAddCourse(r io.Reader) ([]AddCourse, error)

page: addcourse

type Krs added in v0.3.0

type Krs struct {
	MasaKRS string

	MataKuliah []MataKuliahKrs
}

func ScrapeKrs added in v0.3.0

func ScrapeKrs(r io.Reader) (Krs, error)

page: krs

type MataKuliahKrs added in v0.3.0

type MataKuliahKrs struct {
	Kode         string
	MataKuliah   string
	SKS          int
	Keterangan   string
	Kelas        string
	ProgramStudi string
}

type User

type User struct {
	C           *colly.Collector
	Data        UserData
	LoginStatus bool
}

func NewUser

func NewUser() *User

constructor

func (*User) GetData

func (s *User) GetData() error

GetData will fill in user's Data or return an error

func (*User) GetDataAndLogout added in v0.2.0

func (s *User) GetDataAndLogout(username, password string) (UserData, error)

no need to login first & defer logout.

if you just need to get the data and bounce, use this ;)

func (*User) GetKrs added in v0.3.0

func (s *User) GetKrs() (Krs, error)

func (*User) Login

func (s *User) Login(us string, ps string) (string, error)

Please defer Logout() after this function is called

will return a login error message (from siam) and an error (already logged in/login error/siam ui changes/server down/etc)

func (*User) Logout

func (s *User) Logout() error

Make sure to defer this method after login, so the phpsessionid won't be misused

type UserData added in v0.3.0

type UserData struct {
	NIM          string
	Nama         string
	Jenjang      string
	Fakultas     string
	Jurusan      string
	ProgramStudi string
	Seleksi      string
	NomorUjian   string
	FotoProfil   string
}

func ScrapeDataUser added in v0.3.0

func ScrapeDataUser(r io.Reader) (UserData, error)

page: akademik (dashboard)

Directories

Path Synopsis
docs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL