Fixed edge case
This commit is contained in:
69
main.go
69
main.go
@@ -1,80 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/xuri/excelize/v2"
|
|
||||||
"rodbiren.ddns.net/git/robviren/datahop/runner"
|
"rodbiren.ddns.net/git/robviren/datahop/runner"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
exe_path, err := os.Executable()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
work_dir := filepath.Dir(exe_path)
|
|
||||||
|
|
||||||
datahop := runner.NewRunner()
|
datahop := runner.NewRunner()
|
||||||
data := datahop.RunAll()
|
datahop.RunAll()
|
||||||
defer datahop.Close()
|
defer datahop.Close()
|
||||||
|
|
||||||
var f *excelize.File
|
|
||||||
_, err = os.Stat(path.Join(work_dir, "data.xlsx"))
|
|
||||||
if err == nil {
|
|
||||||
f, err = excelize.OpenFile(path.Join(work_dir, "data.xlsx"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
f = excelize.NewFile()
|
|
||||||
f.NewSheet("Facebook")
|
|
||||||
f.NewSheet("Instagram")
|
|
||||||
}
|
|
||||||
|
|
||||||
f.DeleteSheet("Sheet1")
|
|
||||||
|
|
||||||
f.SetCellValue("Facebook", "A1", "Brand")
|
|
||||||
f.SetCellValue("Facebook", "B1", "Followers")
|
|
||||||
f.SetCellValue("Facebook", "C1", "Engagement")
|
|
||||||
f.SetCellValue("Facebook", "D1", "Posts")
|
|
||||||
f.SetCellValue("Facebook", "E1", "Posts")
|
|
||||||
|
|
||||||
f.SetCellValue("Instagram", "A1", "Brand")
|
|
||||||
f.SetCellValue("Instagram", "B1", "Followers")
|
|
||||||
f.SetCellValue("Instagram", "C1", "Engagement")
|
|
||||||
f.SetCellValue("Instagram", "D1", "Posts")
|
|
||||||
f.SetCellValue("Instagram", "E1", "Posts")
|
|
||||||
|
|
||||||
for _, elm := range data {
|
|
||||||
rows, err := f.GetRows(elm.Site)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
f.SetCellValue(elm.Site, "A"+strconv.Itoa(1+len(rows)), elm.Name)
|
|
||||||
f.SetCellValue(elm.Site, "B"+strconv.Itoa(1+len(rows)), elm.Followers)
|
|
||||||
f.SetCellValue(elm.Site, "C"+strconv.Itoa(1+len(rows)), elm.Engagement)
|
|
||||||
f.SetCellValue(elm.Site, "D"+strconv.Itoa(1+len(rows)), elm.Posts)
|
|
||||||
f.SetCellValue(elm.Site, "E"+strconv.Itoa(1+len(rows)), time.Now().Format("01-02-2006"))
|
|
||||||
}
|
|
||||||
|
|
||||||
current_day := time.Now()
|
|
||||||
|
|
||||||
if err := f.SaveAs(path.Join(work_dir, "data-"+current_day.Format("01-02-2006")+".xlsx")); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := f.SaveAs(path.Join(work_dir, "data.xlsx")); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// signal_channel := make(chan os.Signal, 1)
|
|
||||||
// signal.Notify(signal_channel, os.Interrupt)
|
|
||||||
// <-signal_channel
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type InstaPost struct {
|
|||||||
Likes int `json:"likes"`
|
Likes int `json:"likes"`
|
||||||
Views int `json:"views"`
|
Views int `json:"views"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed js/instagram_followers_urls.js
|
//go:embed js/instagram_followers_urls.js
|
||||||
@@ -139,8 +140,10 @@ func (r *Runner) GetIntsaEgagement(urls []string) []InstaPost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.Views != 0 {
|
if res.Views != 0 {
|
||||||
|
res.Type = "Video"
|
||||||
res.Engagement = res.Views + res.Comments
|
res.Engagement = res.Views + res.Comments
|
||||||
} else {
|
} else {
|
||||||
|
res.Type = "Image"
|
||||||
res.Engagement = res.Likes + res.Comments
|
res.Engagement = res.Likes + res.Comments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,28 @@ func NewLogger(work_dir string, weekago time.Time, current_time time.Time) *Logg
|
|||||||
logfile.NewSheet("Facebook")
|
logfile.NewSheet("Facebook")
|
||||||
logfile.NewSheet("Insta")
|
logfile.NewSheet("Insta")
|
||||||
logfile.DeleteSheet("Sheet1")
|
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)
|
var logger = new(Logger)
|
||||||
logger.log = logfile
|
logger.log = logfile
|
||||||
logger.work_dir = work_dir
|
logger.work_dir = work_dir
|
||||||
@@ -41,9 +63,10 @@ func (l *Logger) LogFacebookRes(data FacebookRes, target string) {
|
|||||||
for _, elm := range data.Posts {
|
for _, elm := range data.Posts {
|
||||||
if elm.Timestamp.After(l.weekago) && elm.Timestamp.Before(l.current_time) {
|
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, "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, "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
|
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, "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, "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, "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
|
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, "B"+strconv.Itoa(current_index+1), data.Followers)
|
||||||
l.log.SetCellValue(sheet, "C"+strconv.Itoa(current_index+1), data.Engagement)
|
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, "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() {
|
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)
|
checkErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user