Beispiel #1
0
///func parsePSearch(c appengine.Context, r *io.ReadCloser) (string, os.Error) {
func parsePSearch(c appengine.Context) (string, os.Error) {
	tmp := strings.NewReader(samplePSearchHtml)
	r := &tmp
	n, err := html.Parse(*r)
	if err != nil {
		c.Errorf("%s", err.String())
		return "", err
	}

	nc := NewCursor(n)
	nc = nc.FindById("main1")
	if !nc.Valid {
		printNode(c, n, 0)
		return "", os.NewError("Can't find main1")
	}
	nc.Prune()

	curr := nc.FindChildElement("table").NextSiblingElement("table")
	curr = curr.FindChildElement("tr").NextSiblingElement("tr")
	curr = curr.FindChildElement("input")
	if !curr.Valid {
		return "", os.NewError("Person not found")
	}

	for _, a := range curr.Attr() {
		if a.Key == "onclick" {
			l := strings.Split(a.Val, "'")
			return l[1], nil
		}
	}
	return "", os.NewError("No onclick attribute")
}
Beispiel #2
0
///func parseActDetail(c appengine.Context, r *io.ReadCloser, res *ActDetail) (*ActDetail, os.Error) {
func parseActDetail(c appengine.Context, res *ActDetail) (*ActDetail, os.Error) {
	tmp := strings.NewReader(sampleActHtml)
	r := &tmp
	n, err := html.Parse(*r)
	if err != nil {
		c.Errorf("%s", err.String())
		return nil, err
	}

	nc := NewCursor(n)
	nc = nc.FindById("body1")
	nc.Prune()

	curr := nc.FindText("Activity Type:").Parent().NextSibling().Node.Child[0]
	res.Type = curr.Data

	curr = nc.FindText("Name:").Parent().NextSibling().Node.Child[0]
	res.Name = curr.Data

	curr = nc.FindText("Description:").Parent().NextSibling().Node.Child[0]
	res.Desc = curr.Data

	curr = nc.FindText("Location:").Parent().NextSibling().Node.Child[0]
	res.Location = curr.Data

	curr = nc.FindText("Start Date and Time:").Parent().NextSibling().Node.Child[0]
	res.Start, err = time.Parse("02 Jan 2006\u00a015:04", curr.Data)
	res.Start = time.SecondsToUTC(res.Start.Seconds())
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("Finish Date and Time:").Parent().NextSibling().Node.Child[0]
	res.End, err = time.Parse("02 Jan 2006\u00a015:04", curr.Data)
	res.End = time.SecondsToUTC(res.End.Seconds())
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("No of Cadets:").Parent().NextSibling().Node.Child[0]
	res.NCadets, err = strconv.Atoi(curr.Data)
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("No of Staff:").Parent().NextSibling().Node.Child[0]
	res.NStaff, err = strconv.Atoi(curr.Data)
	if err != nil {
		return nil, err
	}

	return res, nil
}
Beispiel #3
0
///func parsePerson(c appengine.Context, r *io.ReadCloser) (PersDetail, os.Error) {
func parsePerson(c appengine.Context) (PersDetail, os.Error) {
	tmp := strings.NewReader(samplePersonHtml)
	r := &tmp
	n, err := html.Parse(*r)
	if err != nil {
		c.Errorf("%s", err.String())
		return PersDetail{}, err
	}

	nc := NewCursor(n)
	nc = nc.FindById("main1")
	if !nc.Valid {
		printNode(c, n, 0)
		return PersDetail{}, os.NewError("Can't find main1")
	}
	nc.Prune()

	res := PersDetail{}

	curr := nc.FindText("Sex:").FindParentElement("tr")
	res.Sex = curr.Node.Child[1].Child[0].Data[0]

	curr = nc.FindText("Date of Birth:").FindParentElement("tr")
	curr = curr.Child()[1].Child()[0]
	res.Dob, err = time.Parse("02 Jan 2006", curr.Data())
	if err != nil {
		return PersDetail{}, err
	}
	res.Dob = time.SecondsToUTC(res.Dob.Seconds())

	curr = nc.FindText("Home Phone:").FindParentElement("tr")
	if !curr.FindText("Private").Valid {
		res.HomePh = curr.Node.Child[1].Child[0].Data
	}

	curr = nc.FindText("Business Phone:").FindParentElement("tr")
	if !curr.FindText("Private").Valid {
		res.WorkPh = curr.Node.Child[1].Child[0].Data
	}

	curr = nc.FindText("Mobile Phone:").FindParentElement("tr")
	if !curr.FindText("Private").Valid {
		res.Mobile = curr.Node.Child[1].Child[0].Data
	}

	curr = nc.FindText("AAFC Email Address:").FindParentElement("tr")
	res.Email = curr.Node.Child[1].Child[0].Data

	return res, nil
}
Beispiel #4
0
///func parseNomRoll(c appengine.Context, r *io.ReadCloser) (*NomRoll, os.Error) {
func parseNomRoll(c appengine.Context) (*NomRoll, os.Error) {
	tmp := strings.NewReader(sampleRollHtml)
	r := &tmp
	n, err := html.Parse(*r)
	if err != nil {
		c.Errorf("%s", err.String())
		return nil, err
	}

	nc := NewCursor(n)
	nc = nc.FindById("body1")
	if !nc.Valid {
		printNode(c, n, 0)
		return nil, os.NewError("Can't find body1")
	}
	nc.Prune()

	res := &NomRoll{}
	res.Roll = make([]*PersDetail, 0)

	curr := nc.FindChildElement("table")
	for curr = curr.NextSiblingElement("table"); curr.Valid; curr = curr.NextSiblingElement("table") {
		row := curr.FindChildElement("tr").NextSibling()
		for row = row.NextSibling(); row.Valid; row = row.NextSibling() {
			if len(row.Node.Child) == 1 {
				continue
			}

			children := row.Child()
			var p PersDetail
			p.Rank = children[0].Node.Child[0].Data
			p.RankOrder = RankOrder[p.Rank]
			p.FirstName = children[1].Node.Child[0].Data
			p.LastName = children[2].Node.Child[0].Data
			p.ServiceNo = children[3].Node.Child[0].Data
			p.Unit = children[4].Node.Child[0].Data
			res.Roll = append(res.Roll, &p)
		}
	}

	return res, nil
}