예제 #1
0
func makePekarArr(aFP string) ([]*pekar.Pekar, error) {

	log.Println("Parsing " + aFP + " user account file")

	file, err := os.Open(aFP)
	if err != nil {
		return nil, err
	}

	scanner := bufio.NewScanner(file)

	var tmpLineArr []string

	for scanner.Scan() {
		tmpLineArr = append(tmpLineArr, scanner.Text())
	}
	if err = scanner.Err(); err != nil {
		return nil, err
	}

	pLen := int(len(tmpLineArr) / 2)
	pekarna := make([]*pekar.Pekar, pLen, pLen)

	for i := 0; i < pLen; i++ {
		pekarna[i] = pekar.NewPekar(tmpLineArr[i*2], tmpLineArr[i*2+1])
	}

	log.Println(len(pekarna), " Accounts found")

	return pekarna, err
}
예제 #2
0
func main() {

	var (
		err                 error
		feedArr, newFeedArr []*feedEl
	)

	log.Println("Starting...")

	feedURL, login, password, forumID, err := getArgs()

	peka := pekar.NewPekar(login, password)

	if err != nil {
		log.Fatal(err)
	}

	attempts := 0
	for {

		if attempts >= publishAttemptBeforeAborting {
			log.Fatal("Too many publish attempts. Aborting")
		}

		if newFeedArr, err = checkFeed(feedURL); err != nil {
			attempts++
			log.Println(err)
			continue
		}

		feedArr = append(feedArr, newFeedArr...)

		tmpFArr := make([]*feedEl, 0)

		for _, e := range feedArr {

			var aBBCodeBody string

			if aBBCodeBody, err = getArticle(e.url); err != nil {
				tmpFArr = append(tmpFArr, e)
				log.Println(err)
				continue
			}

			if err = publishArticle(e.title, aBBCodeBody,
				forumID, peka); err != nil {
				tmpFArr = append(tmpFArr, e)
				log.Println(err)
				continue
			}
		}

		feedArr = tmpFArr
		if len(tmpFArr) > 0 {
			attempts++
			continue
		}

		attempts = 0

		time.Sleep(feedRefreshDelay)
	}
}