Exemplo n.º 1
0
func (this *Pixivspy) checkLogin() bool {
	req, err := http.NewRequest(config.Info.CheckLoginPageUrl.Method,
		config.Info.CheckLoginPageUrl.Url,
		nil)

	if err != nil {
		log4go.Debug("可能也许大概内存不足导致发送请求失败!")
		os.Exit(-1)
	}

	log4go.Info("登录中")

	this.setHtmlHeader(req)

	body, err := this.download(req)
	if err != nil {
		return false
	}

	query, err := goquery.ParseString(string(body))
	if err != nil {
		log4go.Error("解析登录数据失败", this.username)
		return false
	}

	item := query.Find(".user")
	if item.Length() == 0 {
		return false
	}

	return true
}
Exemplo n.º 2
0
func TestLog4Go1() {

	l4g.Error("..RRR.")
	l4g.Warn("...")
	log := l4g.NewLogger()
	defer log.Close()
	log.AddFilter("stdout", l4g.WARNING, l4g.NewConsoleLogWriter())
	log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
}
Exemplo n.º 3
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"
	log.Debug("log4go by %s", name)
	log.Info("log4go by %s", name)
	log.Warn("log4go by %s", name)
	log.Error("log4go by %s", name)
	log.Fatal("log4go by %s", name)
}
Exemplo n.º 4
0
func (con *Connection) receiveLoop() {
	for {
		log.Finest("Waiting for packet..")
		packet, err := packets.ReadPacket(con.conn)
		if err != nil {
			log.Error("Failure in receive loop: %v", err)
			return
		}
		log.Fine("got packet %v", packet.PacketID())

		// put into receive queue
		con.Session.RXQueue <- packet
	}
}
Exemplo n.º 5
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"

	for {
		log.Debug("log4go by %s", name)
		log.Info("log4go by %s", name)
		log.Warn("log4go by %s", name)
		log.Error("log4go by %s", name)
		log.Fatal("log4go by %s", name)

		time.Sleep(time.Second * 1)
	}
}
Exemplo n.º 6
0
func (sess *Session) handlerLoop() {
	for {
		// wait for packet
		packet := <-sess.RXQueue

		// get the handler
		handler := sess.handlers[packet.PacketID()]

		// try to run handler
		if handler != nil {
			handler(sess, packet)
		} else {
			log.Error("Handler for %v not found!", packet.PacketID())
		}
	}
}
Exemplo n.º 7
0
func (this *Pixivspy) Login() bool {
	postValue := url.Values{}
	postValue.Set("mode", "login")
	postValue.Add("pixiv_id", this.username)
	postValue.Add("pass", this.password)
	postValue.Add("skip", "1")

	req, err := http.NewRequest(config.Info.LoginPageUrl.Method,
		config.Info.LoginPageUrl.Url,
		strings.NewReader(postValue.Encode()))

	if err != nil {
		log4go.Debug("可能也许大概内存不足导致发送请求失败!")
		return false
	}

	log4go.Info("正在登录: %s", this.username)

	this.setHtmlHeader(req)

	client := http.Client{Jar: this.cookie}

	resp := &http.Response{}
	retry := 0
	for retry < 5 {
		resp, err = client.Do(req)
		if err == nil {
			break
		}

		if resp != nil {
			resp.Body.Close()
		}

		retry++
	}

	if retry == 5 || !this.checkLogin() {
		log4go.Error("帐号: %s 登录失败", this.username)
		return false
	}

	log4go.Info("帐号: %s 登录成功", this.username)

	return true
}
Exemplo n.º 8
0
func (this *Pixivspy) parseStarPage(url string) []string {
	members := []string{}

	for i := 1; true; i++ {
		url = fmt.Sprintf(url+"&p=%d", i)

		req, _ := http.NewRequest(config.Info.StarPageUrl.Method, url, nil)

		this.setHtmlHeader(req)

		page, err := this.download(req)
		if page == nil || err != nil {
			log4go.Error("下载关注页面失败")
			break
		}

		query, err := goquery.ParseString(string(page))
		if err != nil {
			log4go.Debug("解析关注页面失败")
			break
		}

		membersItem := query.Find("div.userdata")

		if membersItem.Length() == 0 {
			break
		}

		log4go.Info("正在解析第[%d]页关注页面", i)

		for i := 0; i < membersItem.Length(); i++ {
			a := membersItem.Eq(i)
			memberID := a.Find("a").Attr("data-user_id")
			members = append(members, memberID)
		}
	}

	return members
}
Exemplo n.º 9
0
func main() {
	defer log4go.Close()

	pixiv := pixivspy.NewPixivspy(config.Info.User, config.Info.Password)

	if !pixiv.Login() {
		return
	}

	downloadPath := util.FixPathName(config.Info.DownloadPath)

	log4go.Info("检查下载目录: %s", downloadPath)
	if !util.CheckFileIsExist(downloadPath) {
		log4go.Info("创建下载目录: %s", downloadPath)
		os.MkdirAll(downloadPath, 0777)
	}

	switch config.Info.Mode {
	case "id":
		for _, id := range config.Info.IDS {
			pixiv.DownloadMemberIllusts(id)
		}
	case "star":
		if len(config.Info.IDS) == 0 {
			pixiv.DownloadStar("")
		} else {
			for _, id := range config.Info.IDS {
				pixiv.DownloadStar(id)
			}
		}
	default:
		log4go.Error("Mode必须为[star | id]")
	}

	pixiv.WaitDownload()
}