Пример #1
0
//下载图片
func (self *PipelineMySQL) imgProcess(pageitems *robot.PageItems, task robot.Task) string {
	if img, ok := pageitems.GetItem("img"); ok {
		filename, _ := utils.DownloadImage(img, self.ImageStore)
		return filename
	}
	return ""
}
Пример #2
0
Файл: mgo.go Проект: aosen/robot
func (self *PipelineMongo) Process(pageitems *robot.PageItems, task robot.Task) {
	items := Items{}
	items.Test1, _ = pageitems.GetItem("test1")
	items.Test2, _ = pageitems.GetItem("test2")
	err := self.c.Insert(&items)
	if err != nil {
		panic(err)
	}
}
Пример #3
0
func (self *PipelineMySQL) Process(pageitems *robot.PageItems, task robot.Task) {
	if code, ok := pageitems.GetItem("code"); ok && code == "0" {
		firstid := self.firstProcess(pageitems, task)
		secondid := self.secondProcess(pageitems, task)
		picname := self.imgProcess(pageitems, task)
		if novelid, err := self.novelProcess(pageitems, task, firstid, secondid, picname); err == nil {
			self.contentProcess(pageitems, task, novelid, firstid, secondid)
		} else {
			log.Println(err.Error())
		}
	}
}
Пример #4
0
//如果二级分类存在则略过,不存在存储
func (self *PipelineMySQL) secondProcess(pageitems *robot.PageItems, task robot.Task) int64 {
	if secondname, ok := pageitems.GetItem("second"); ok {
		o := orm.NewOrm()
		second := &Second{
			Secondname: secondname,
			Createtime: time.Now(),
			Updatetime: time.Now(),
		}
		//如果数据不存在 则创建
		if _, id, err := o.ReadOrCreate(second, "secondname"); err == nil {
			return id
		}
	}
	return -1
}
Пример #5
0
//如果一级分类标签存在则略过,
//不存在则将一级分类标签插入数据库,并存储一级分类标签的id
func (self *PipelineMySQL) firstProcess(pageitems *robot.PageItems, task robot.Task) int64 {
	if firstname, ok := pageitems.GetItem("first"); ok {
		o := orm.NewOrm()
		first := &First{
			Firstname:  firstname,
			Createtime: time.Now(),
			Updatetime: time.Now(),
		}
		if _, id, err := o.ReadOrCreate(first, "firstname"); err == nil {
			return id
		}

	}
	return -1
}