Exemple #1
0
func FetchPreview(code int, tweet *anaconda.Tweet, config Config) {
	coverUrls := PeekCoverImageUrls(code, config.HaruHostName)
	now := time.Now()

	// 커버는 1개일 확률이 높으니까 고루틴 굳이 쓸 필요 없을거다
	for i, url := range coverUrls {
		fetcher := network.HttpFetcher{}
		resp := fetcher.Fetch(url)

		prefix := twutils.MakePrefix(now)
		filename := ""
		ext := filepath.Ext(url)
		if len(coverUrls) == 1 {
			filename = fmt.Sprintf("%d%s", code, ext)
		} else {
			num := i + 1
			filename = fmt.Sprintf("%d_%d%s", code, num, ext)
		}
		config.Accessor.UploadBytes(resp.Data, prefix+filename)
	}

	if tweet != nil && len(coverUrls) > 0 {
		twutils.UploadMetadata(tweet, config.Accessor, "", now)
	}
}
Exemple #2
0
func save(tweet *anaconda.Tweet, mediaRespList []*MediaResponse, accessor storages.Accessor) {
	now := time.Now()

	resp, e := twutils.UploadMetadata(tweet, accessor, "", now)
	if e != nil {
		log.Fatalf("Save Tweet Fail! %s -> %s, [%s]", resp.ID, resp.FileName, e.Error())
	} else {
		log.Printf("Save Tweet %s -> %s", resp.ID, resp.FileName)
	}

	// upload media
	for _, resp := range mediaRespList {
		filename := twutils.MakeNormalFileName(resp.FileName, now)
		err := accessor.UploadBytes(resp.Response.Data, filename)
		if err != nil {
			log.Fatalf("Save Image Fail! %s -> %s, [%s]", tweet.IdStr, filename, err.Error())
		} else {
			log.Printf("Save Image %s -> %s", tweet.IdStr, filename)
		}
	}
}