-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:compare file to old ad file before create new commit
- Loading branch information
1 parent
418107e
commit 95f9af3
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GH_OWNER= | ||
GH_REPO= | ||
GH_API_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"strings" | ||
) | ||
|
||
const adFileName = "ads.txt" | ||
const tmpFileName = "ads.tmp.txt" | ||
|
||
func getExisitngUrlList() string { | ||
exisitingAdFileBuf, err := ioutil.ReadFile(adFileName) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
exisitingAdFile := string(exisitingAdFileBuf) | ||
return exisitingAdFile | ||
} | ||
|
||
func makeSetFromList(list string) map[string]bool { | ||
set := make(map[string]bool) | ||
listSplit := strings.Split(list, "\n") | ||
|
||
for _, listItem := range listSplit { | ||
if listItem != "" && !strings.HasPrefix(listItem, "#") { | ||
var url string | ||
urlSplit := strings.Split(listItem, " ") | ||
// handle string - 0.0.0.0 somewebsite | ||
if strings.HasPrefix("0.0.0", listItem) { | ||
url = urlSplit[1] | ||
} else { | ||
// handle strings | ||
// 1- googel.com | ||
// 2- google.com # google | ||
url = urlSplit[0] | ||
} | ||
|
||
fmt.Println(url, listItem, urlSplit) | ||
|
||
set[url] = true | ||
} | ||
} | ||
|
||
return set | ||
} | ||
|
||
func IsBlockListSame(newUrlList string) bool { | ||
oldSet := makeSetFromList(getExisitngUrlList()) | ||
newSet := makeSetFromList(newUrlList) | ||
|
||
isSame := true | ||
|
||
for k, _ := range newSet { | ||
fmt.Println(k) | ||
isSame = oldSet[k] | ||
|
||
if !isSame { | ||
break | ||
} | ||
} | ||
fmt.Println("is Same", isSame) | ||
return isSame | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/hlubek/readercomp v0.0.0-20210927065201-8f5e69adbe1c h1:XNU2fYUmgiQD+V/9FYiBhM/XbsTYR/MFB/4AirnW/1w= | ||
github.com/hlubek/readercomp v0.0.0-20210927065201-8f5e69adbe1c/go.mod h1:lax9oGcMHTg+S5EV4vttUkL3qam+ILZrDOeTmhOEXCA= | ||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= | ||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= | ||
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters