ming800

package module
v0.0.0-...-6103d37 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: MIT Imports: 10 Imported by: 3

README

ming800

Build Status Go Report Card GoDoc

ming800是一个Golang包,提供适用于旧单机版本明日管理系统的API接口。

适用版本
  • 旧版单机安装版本(2012年)
  • 只有1个校区(总部)
工作方式
  • 抓取网页结果,并且使用正则表达式得到数据。
功能
  • 迭代当前所有专业与开设班级,以及每个班级的学生信息。
例子:迭代ming800的所有年级,班级,学生信息
    // MyProcessor implements ming800.Processor interface to walk ming800.
    type MyProcessor struct {
    }

    func (p *MyProcessor) ClassHandler(class ming800.Class) {
            log.Printf("class: %v", class)
    }

    func (p *MyProcessor) StudentHandler(class ming800.Class, student ming800.Student) {
            log.Printf("class: %v, student: %v", class, student)
    }

    // New a session
    s, _ := ming800.NewSession(ServerURL, Company, User, Password); err != nil {

    // Login
    s.Login()

    // Walk
    processor := &MyProcessor{}
    s.Walk(processor)

    // Logout
    s.Logout()
文档
License

Documentation

Overview

Example

Run "go test -c && ./ming800.test" to load config.json and do the test.

package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"path"

	"github.com/northbright/ming800"
	"github.com/northbright/pathhelper"
)

// MyProcessor implements ming800.Processor interface to walk ming800.
type MyProcessor struct {
}

func (p *MyProcessor) ClassHandler(class *ming800.Class) error {
	log.Printf("class: %v", class)
	return nil
}

func (p *MyProcessor) StudentHandler(class *ming800.Class, student *ming800.Student) error {
	log.Printf("class: %v, student: %v", class, student)
	return nil
}

// Run "go test -c && ./ming800.test" to load config.json and do the test.
func main() {
	// 1. Create a "config.json" like this to load settings:
	/*{
	        "server_url": "http://localhost:8080",
		"company": "my_company",
		"user": "Frank",
		"password": "my_password"
	}*/

	// 2. Run "go test -c && ./ming800.test" to load config.json and do the test.

	type Config struct {
		ServerURL string `json:"server_url"`
		Company   string `json:"company"`
		User      string `json:"user"`
		Password  string `json:"password"`
	}

	var (
		err                    error
		buf                    []byte
		currentDir, configFile string
		s                      *ming800.Session
		config                 Config
	)

	defer func() {
		if err != nil {
			log.Printf("%v", err)
		}
	}()

	currentDir, _ = pathhelper.GetCurrentExecDir()
	configFile = path.Join(currentDir, "config.json")

	// Load Conifg
	if buf, err = ioutil.ReadFile(configFile); err != nil {
		err = fmt.Errorf("load config file error: %v", err)
		return
	}

	if err = json.Unmarshal(buf, &config); err != nil {
		err = fmt.Errorf("parse config err: %v", err)
		return
	}

	// New a session
	if s, err = ming800.NewSession(config.ServerURL, config.Company, config.User, config.Password); err != nil {
		err = fmt.Errorf("NewSession() error: %v", err)
		return
	}

	// Login
	if err = s.Login(); err != nil {
		err = fmt.Errorf("Login() error: %v", err)
		return
	}

	log.Printf("Login() successfully.\n")

	// Walk
	// Class and student handler will be called while walking ming800.
	processor := &MyProcessor{}
	if err = s.Walk(processor); err != nil {
		err = fmt.Errorf("Walk() error: %v", err)
		return
	}

	// Logout
	if err = s.Logout(); err != nil {
		err = fmt.Errorf("Logout() error: %v", err)
		return
	}

	log.Printf("logout() successfully.\n")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class struct {
	// Name is name of the class.
	Name string
	// Category is the category of the class.
	Category string
	// Teachers are the teachers of the class. One class can have multiple teachers.
	Teachers []string
	// ClassRoom is the class room of the class.
	ClassRoom string
	// Periods are the periods of the class.
	// One class may have 2 or more periods.
	Periods []string
}

Class represents class information.

type Session

type Session struct {
	// ServerURL is the server base URL of ming800.
	ServerURL string
	// Company is the company(orgnization) name for login.
	Company string
	// User is the user name of ming800.
	User string
	// Password is the user's password.
	Password string

	// LoggedIn represents login status.
	LoggedIn bool
	// contains filtered or unexported fields
}

Session represents the login session and provides methods to interactive with ming800.

func NewSession

func NewSession(serverURL, company, user, password string) (s *Session, err error)

NewSession creates a new session of ming800.

func (*Session) GetStudentDetails

func (s *Session) GetStudentDetails(ID string) (map[string]string, error)

func (*Session) GetViewStudentURL

func (s *Session) GetViewStudentURL(ID string) string

GetViewStudentURL returns the URL of view student which response contains details of the student include customized column(e.g. ID card number).

func (*Session) Login

func (s *Session) Login() (err error)

Login performs the login action.

func (*Session) Logout

func (s *Session) Logout() (err error)

Logout performs the log out action.

func (*Session) Walk

func (s *Session) Walk(processor WalkProcessor) error

Walk walks through the ming800.

type Student

type Student struct {
	// ID is the internal ID of student.
	ID string
	// Name is the name of student.
	Name string
	// PhoneNum is the phone number of the contact for the student.
	PhoneNum string
	// Details store student information in key-value map.
	Details map[string]string
}

Student represeents the student information.

type WalkProcessor

type WalkProcessor interface {
	// ClassHandler is the callback when a class is found.
	ClassHandler(class *Class) error
	// StudentHandler is the callback when a student is found.
	StudentHandler(class *Class, student *Student) error
}

WalkProcessor interface need users to implement callback functions while walking ming800.

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

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