Fixed edge case

This commit is contained in:
2021-11-02 16:12:44 -05:00
parent 1ddbca8352
commit f9ac3ec934
3 changed files with 32 additions and 72 deletions

View File

@@ -23,6 +23,28 @@ func NewLogger(work_dir string, weekago time.Time, current_time time.Time) *Logg
logfile.NewSheet("Facebook")
logfile.NewSheet("Insta")
logfile.DeleteSheet("Sheet1")
logfile.SetCellValue("Facebook", "A1", "Brand")
logfile.SetCellValue("Facebook", "B1", "Followers")
logfile.SetCellValue("Facebook", "C1", "Engagement")
logfile.SetCellValue("Facebook", "D1", "Posts")
logfile.SetCellValue("Insta", "A1", "Brand")
logfile.SetCellValue("Insta", "B1", "Followers")
logfile.SetCellValue("Insta", "C1", "Engagement")
logfile.SetCellValue("Insta", "D1", "Posts")
logfile.SetCellValue("InstaPosts", "A1", "Brand")
logfile.SetCellValue("InstaPosts", "B1", "URL")
logfile.SetCellValue("InstaPosts", "C1", "Engagement")
logfile.SetCellValue("InstaPosts", "D1", "Date")
logfile.SetCellValue("InstaPosts", "E1", "Type")
logfile.SetCellValue("FacebookPosts", "A1", "Brand")
logfile.SetCellValue("FacebookPosts", "B1", "URL")
logfile.SetCellValue("FacebookPosts", "C1", "Engagement")
logfile.SetCellValue("FacebookPosts", "D1", "Date")
var logger = new(Logger)
logger.log = logfile
logger.work_dir = work_dir
@@ -41,9 +63,10 @@ func (l *Logger) LogFacebookRes(data FacebookRes, target string) {
for _, elm := range data.Posts {
if elm.Timestamp.After(l.weekago) && elm.Timestamp.Before(l.current_time) {
l.log.SetCellValue(log_facebook_sheet, "A"+strconv.Itoa(current_index+1), target)
l.log.SetCellValue(log_facebook_sheet, "D"+strconv.Itoa(current_index+1), elm.Timestamp.Format("01-02-2006"))
l.log.SetCellValue(log_facebook_sheet, "C"+strconv.Itoa(current_index+1), elm.Engagement)
l.log.SetCellValue(log_facebook_sheet, "B"+strconv.Itoa(current_index+1), elm.URL)
l.log.SetCellValue(log_facebook_sheet, "C"+strconv.Itoa(current_index+1), elm.Engagement)
l.log.SetCellValue(log_facebook_sheet, "D"+strconv.Itoa(current_index+1), elm.Timestamp.Format("01-02-2006"))
current_index += 1
}
}
@@ -59,6 +82,7 @@ func (l *Logger) LogInstaRes(posts []InstaPost, target string) {
l.log.SetCellValue(log_insta_sheet, "B"+strconv.Itoa(current_index+1), elm.URL)
l.log.SetCellValue(log_insta_sheet, "C"+strconv.Itoa(current_index+1), elm.Engagement)
l.log.SetCellValue(log_insta_sheet, "D"+strconv.Itoa(current_index+1), elm.Timestamp.Format("01-02-2006"))
l.log.SetCellValue(log_insta_sheet, "E"+strconv.Itoa(current_index+1), elm.Type)
current_index += 1
}
}
@@ -72,10 +96,10 @@ func (l *Logger) LogResult(data Result, sheet string) {
l.log.SetCellValue(sheet, "B"+strconv.Itoa(current_index+1), data.Followers)
l.log.SetCellValue(sheet, "C"+strconv.Itoa(current_index+1), data.Engagement)
l.log.SetCellValue(sheet, "D"+strconv.Itoa(current_index+1), data.Posts)
l.log.SetCellValue(sheet, "E"+strconv.Itoa(current_index+1), time.Now().Format("01-02-2006"))
// l.log.SetCellValue(sheet, "E"+strconv.Itoa(current_index+1), time.Now().Format("01-02-2006"))
}
func (l *Logger) Close() {
err := l.log.SaveAs(path.Join(l.work_dir, "log-"+time.Now().Format("01-02-2006")+".xlsx"))
err := l.log.SaveAs(path.Join(l.work_dir, "data-"+time.Now().Format("01-02-2006")+".xlsx"))
checkErr(err)
}