Skip to content

Commit

Permalink
Merge pull request #4 from tarekbadrshalaan/feat/GUI/Add_GUI
Browse files Browse the repository at this point in the history
feature add gui :)
  • Loading branch information
tarekbadrsh authored May 23, 2021
2 parents 89b4bba + cbe3373 commit f77d6cc
Show file tree
Hide file tree
Showing 55 changed files with 8,120 additions and 173 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
result

twfinder
twfinder.exe
config.json
.out

Expand Down
22 changes: 16 additions & 6 deletions Ubuntu_Users/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@
"ACCESS_TOKEN": "<ACCESS_TOKEN>",
"ACCESS_TOKEN_SECRET": "<ACCESS_TOKEN_SECRET>",
"SEARCH_USER": "<SEARCH_USER>",
"TWITTER_LIST": {
"SAVE_LIST": true,
"LIST_NAME": "New-list",
"IS_PUBLIC": false,
"LIST_DESCRIPTION": "my new list"
},
"SEARCH_CRITERIA": {
"SEARCH_HANDLE_CONTEXT": [
"adam",
"erik"
"erik",
"-ali"
],
"SEARCH_NAME_CONTEXT": [
"dr",
"mr"
"mr",
"-eng"
],
"SEARCH_BIO_CONTEXT": [
"Develper",
"CEO",
"Linux",
"technology"
"technology",
"-doctor"
],
"SEARCH_LOCATION_CONTEXT": [
"Berlin",
"Gothenburg"
"Gothenburg",
"-cairo"
],
"FOLLOWERS_COUNT_BETWEEN": {
"FROM": 0,
Expand All @@ -47,10 +57,10 @@
"FROM": "2000-09-22T12:42:31Z",
"TO": "2018-09-22T12:42:31Z"
},
"VERIFIED": true
"VERIFIED": false
},
"FOLLOWING": true,
"FOLLOWERS": false,
"FOLLOWERS": true,
"RECURSIVE": true,
"CONTINUE_SUCCESS_USERS_ONLY": true
}
22 changes: 16 additions & 6 deletions Windows_Users/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@
"ACCESS_TOKEN": "<ACCESS_TOKEN>",
"ACCESS_TOKEN_SECRET": "<ACCESS_TOKEN_SECRET>",
"SEARCH_USER": "<SEARCH_USER>",
"TWITTER_LIST": {
"SAVE_LIST": true,
"LIST_NAME": "New-list",
"IS_PUBLIC": false,
"LIST_DESCRIPTION": "my new list"
},
"SEARCH_CRITERIA": {
"SEARCH_HANDLE_CONTEXT": [
"adam",
"erik"
"erik",
"-ali"
],
"SEARCH_NAME_CONTEXT": [
"dr",
"mr"
"mr",
"-eng"
],
"SEARCH_BIO_CONTEXT": [
"Develper",
"CEO",
"Linux",
"technology"
"technology",
"-doctor"
],
"SEARCH_LOCATION_CONTEXT": [
"Berlin",
"Gothenburg"
"Gothenburg",
"-cairo"
],
"FOLLOWERS_COUNT_BETWEEN": {
"FROM": 0,
Expand All @@ -47,10 +57,10 @@
"FROM": "2000-09-22T12:42:31Z",
"TO": "2018-09-22T12:42:31Z"
},
"VERIFIED": true
"VERIFIED": false
},
"FOLLOWING": true,
"FOLLOWERS": false,
"FOLLOWERS": true,
"RECURSIVE": true,
"CONTINUE_SUCCESS_USERS_ONLY": true
}
Binary file modified Windows_Users/twfinder.exe
Binary file not shown.
26 changes: 15 additions & 11 deletions config.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
"ACCESS_TOKEN": "<ACCESS_TOKEN>",
"ACCESS_TOKEN_SECRET": "<ACCESS_TOKEN_SECRET>",
"SEARCH_USER": "<SEARCH_USER>",
"TWITTER_LIST": {
"SAVE_LIST": true,
"LIST_NAME": "<LIST_NAME>",
"IS_PUBLIC": false,
"LIST_DESCRIPTION": "<LIST_DESCRIPTION>"
},
"SEARCH_CRITERIA": {
"SEARCH_HANDLE_CONTEXT": [
"adam",
"erik"
"a",
"-a"
],
"SEARCH_NAME_CONTEXT": [
"dr",
"mr"
"a",
"-a"
],
"SEARCH_BIO_CONTEXT": [
"Developer",
"CEO",
"Linux",
"technology"
"a",
"-a"
],
"SEARCH_LOCATION_CONTEXT": [
"Berlin",
"Gothenburg"
"a",
"-a"
],
"FOLLOWERS_COUNT_BETWEEN": {
"FROM": 0,
Expand Down Expand Up @@ -50,7 +54,7 @@
"VERIFIED": true
},
"FOLLOWING": true,
"FOLLOWERS": false,
"FOLLOWERS": true,
"RECURSIVE": true,
"RECURSIVE_SUCCESS_USERS_ONLY": true
}
120 changes: 100 additions & 20 deletions config/configuration.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package config

import (
"encoding/json"
"fmt"
"sync"
"os"
"time"

"github.com/kelseyhightower/envconfig"
"github.com/tarekbadrshalaan/goStuff/configuration"
)

var (
readConfigOnce sync.Once
internalConfig Config
)

// Config : application configuration
type Config struct {
ConsumerKey string `json:"CONSUMER_KEY" envconfig:"CONSUMER_KEY"`
ConsumerSecret string `json:"CONSUMER_SECRET" envconfig:"CONSUMER_SECRET"`
AccessToken string `json:"ACCESS_TOKEN" envconfig:"ACCESS_TOKEN"`
AccessTokenSecret string `json:"ACCESS_TOKEN_SECRET" envconfig:"ACCESS_TOKEN_SECRET"`
SearchUser string `json:"SEARCH_USER" envconfig:"SEARCH_USER"`
TwitterList TwitterList `json:"TWITTER_LIST" envconfig:"TWITTER_LIST"`
SearchCriteria SearchCriteria `json:"SEARCH_CRITERIA" envconfig:"SEARCH_CRITERIA"`
Following bool `json:"FOLLOWING" envconfig:"FOLLOWING"`
Followers bool `json:"FOLLOWERS" envconfig:"FOLLOWERS"`
Expand All @@ -43,6 +40,14 @@ type SearchCriteria struct {
Verified bool `json:"VERIFIED" envconfig:"VERIFIED"`
}

// TwitterList : twitter list to store the result
type TwitterList struct {
SaveList bool `json:"SAVE_LIST" envconfig:"SAVE_LIST"`
Name string `json:"LIST_NAME" envconfig:"LIST_NAME"`
IsPublic bool `json:"IS_PUBLIC" envconfig:"IS_PUBLIC"`
Description string `json:"LIST_DESCRIPTION" envconfig:"LIST_DESCRIPTION"`
}

// FromToNumber : From-To-Number
type FromToNumber struct {
From int64 `json:"FROM" envconfig:"FROM"`
Expand All @@ -55,20 +60,95 @@ type FromToDate struct {
To time.Time `json:"TO" envconfig:"TO"`
}

// Configuration : get configuration based on json file or environment variables
func Configuration() Config {
readConfigOnce.Do(func() {
err := configuration.JSON("config.json", &internalConfig)
if err == nil {
return
}
fmt.Println(err)
var (
configPath = ""
internalConfig = Config{}

defaultConfigPath = "config.json"
defaultConfiguration = Config{
ConsumerKey: "<CONSUMER_KEY>",
ConsumerSecret: "<CONSUMER_SECRET>",
AccessToken: "<ACCESS_TOKEN>",
AccessTokenSecret: "<ACCESS_TOKEN_SECRET>",
SearchUser: "<SEARCH_USER>",
TwitterList: TwitterList{
SaveList: true,
Name: fmt.Sprintf("Twfinder-%v", time.Now()),
Description: "Twitter finder list (default name)",
IsPublic: false,
},
SearchCriteria: SearchCriteria{
SearchHandleContext: []string{"a", "-a"},
SearchNameContext: []string{"a", "-a"},
SearchBioContext: []string{"a", "-a"},
SearchLocationContext: []string{"a", "-a"},
FollowersCountBetween: FromToNumber{From: 0, To: 100000},
FollowingCountBetween: FromToNumber{From: 0, To: 100000},
LikesCountBetween: FromToNumber{From: 0, To: 100000},
TweetsCountBetween: FromToNumber{From: 0, To: 100000},
ListsCountBetween: FromToNumber{From: 0, To: 100000},
JoinedBetween: FromToDate{From: time.Time{}, To: time.Now()},
Verified: false,
},
Following: true,
Followers: true,
Recursive: true,
RecursiveSuccessUsersOnly: true,
}
)

err = envconfig.Process("", &internalConfig)
if err != nil {
err = fmt.Errorf("Error while initiating app configuration : %v", err)
panic(err)
}
})
// BuildConfiguration : cp Configuration path
func BuildConfiguration(cp string) {
if cp != "" {
configPath = cp
} else {
configPath = defaultConfigPath
}

// get configuration from json file
if err := configuration.JSON(configPath, &internalConfig); err == nil {
return
}
// get configuration from environment variables
if err := envconfig.Process("", internalConfig); err == nil {
return
}
fmt.Printf(
"Error occurred during build the configuration from '%v' & environment variables"+
"\n <<<DEFAULT CONFIGURATION WILL BE USED>>>\n", configPath)
internalConfig = defaultConfiguration
}

// Configuration : get the current available configuration
func Configuration() Config {
// todo check if internalConfig is nil, and rebuild
return internalConfig
}

// SetConfiguration : set the configuration
func SetConfiguration(c Config) {
internalConfig = c
}

// SaveConfiguration : the current available configuration
// cp Configuration file path to save
func SaveConfiguration(cp string) error {
if cp == "" {
// use current configPath
cp = configPath
}
f, err := os.OpenFile(cp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
fmt.Printf("Error occurred during open file %v %v\n", cp, err)
return err
}
defer f.Close()

jsonToSave, err := json.MarshalIndent(internalConfig, "", " ")
if err != nil {
fmt.Printf("Error occurred during Marshal json %v\n", err)
return err
}
f.Write(jsonToSave)
return nil
}
18 changes: 15 additions & 3 deletions finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"sync"
"twfinder/config"
helper "twfinder/helpers"
"twfinder/helper"

"github.com/tarekbadrshalaan/anaconda"
)
Expand Down Expand Up @@ -44,8 +44,12 @@ func CheckUserCriteria(user *anaconda.User) bool {
}

// BuildSearchCriteria : build interanl search criteria
func BuildSearchCriteria(c config.Config) {
func BuildSearchCriteria() {
c := config.Configuration()
buildFinderOnce.Do(func() {
// all accounts in the system should not be protected
intFinder.filters = append(intFinder.filters, protectedFilter)

intFinder.searchHandleContext = c.SearchCriteria.SearchHandleContext
if len(intFinder.searchHandleContext) > 1 {
intFinder.filters = append(intFinder.filters, handleFilter)
Expand Down Expand Up @@ -226,7 +230,7 @@ func listsFilter(u *anaconda.User) (string, bool) {

func joinedFilter(u *anaconda.User) (string, bool) {
match := true
joinedUnx := helper.StringtoDate(u.CreatedAt).Unix()
joinedUnx := helper.StringtoDate(u.CreatedAt, "").Unix()
if !intFinder.joinedBetween.From.IsZero() {
if joinedUnx <= intFinder.joinedBetween.From.Unix() {
match = false
Expand All @@ -247,3 +251,11 @@ func verifiedFilter(u *anaconda.User) (string, bool) {
}
return "VERIFIED", match
}

func protectedFilter(u *anaconda.User) (string, bool) {
match := true
if u.Protected {
match = false
}
return "PROTECTED", match
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/tarekbadrshalaan/anaconda v2.0.0+incompatible
github.com/tarekbadrshalaan/anaconda v2.0.2+incompatible
github.com/tarekbadrshalaan/goStuff v1.1.1
go.uber.org/zap v1.9.1
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
Expand Down
Loading

0 comments on commit f77d6cc

Please sign in to comment.