Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
nonotest committed Nov 25, 2018
0 parents commit 3de90ab
Show file tree
Hide file tree
Showing 276 changed files with 70,067 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_TOKEN_SECRET=
TWITTER_USERNAME=
IG_USERNAME=
IG_PASSWORD=
IG_COOKIE_PATH=
REDIS_ADDRESS=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
FACEBOOK_PAGE_NAME=
SHORT_LIVED_FACEBOOK_TOKEN=
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
token.json
credentials.json
.env
igcookie
133 changes: 133 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/ChimeraCoder/anaconda"
version = "2.0.0"

[[constraint]]
name = "github.com/garyburd/redigo"
version = "1.6.0"

[[constraint]]
name = "github.com/huandu/facebook"
version = "2.3.2"

[[constraint]]
name = "github.com/joho/godotenv"
version = "1.3.0"

[[constraint]]
branch = "master"
name = "golang.org/x/oauth2"

[[constraint]]
branch = "master"
name = "google.golang.org/api"

[[constraint]]
name = "gopkg.in/ahmdrz/goinsta.v2"
version = "2.3.0"

[prune]
go-tests = true
unused-packages = true
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Disclaimer

This is a random script that served some internal usage.
Nothing fancy to see!

Not much err checking/logging so dont panic if you see random panics. (PUN!)

# Setup

Run `docker-compose up` if you need a local redis instance.
At the moment the only datastore is redis to simplify things.

Copy `.env.example` to `.env` and fill whatever you need.

Later we should be able to split the package to offer:

- a command line tool to import data
- a rest api + a web ui to visualise/export the data

Examples:

`go run main.go --mode=import --source=instagram --source=twitter`

Will import list of users that follow you or you are following on IG/Twitter
with whatever details we can get.

`go run main.go --mode=export --source=instagram --source=twitter`

Will create a google sheet with the exported details.
There is a filter view available that allow you to sort ASC/DESC the data!

Deps with `dep`

# Sources

We can import followers from the list below;

## INSTAGRAM

If you want to use IG run `go run export-insta.go` first to create a cookie.
The cookie will be used so you dont have to login/logout all the time.

Unknown rate limit

## TWITTER

Twitter developer account (for twitter).

## FB

Turns out you cant really get anything interesting from this.
No more friends, no more subscribes/fans to a page...

Get a page or page app token.

via `https://developers.facebook.com/tools/explorer/`

## LINKEDIN

TODO

# Export

We can export to

## GOOGLE SHEET

Export takes 2 params: depth (how many levels do you want to go through (may be expensive in api calls))
baseScreenName, what to use to query first level.
32 changes: 32 additions & 0 deletions cmd/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"

"github.com/athletifit/social-network-insights/datastore"
"github.com/athletifit/social-network-insights/export"
"github.com/athletifit/social-network-insights/models"
)

func ExportData(sourcesPtr models.ArrayFlags) {
store := datastore.NewRedisDataStore()

// fixme change to users
sets := make([]models.DataSet, 0, 1)

for _, s := range sourcesPtr {
users, err := store.LoadUsers(s)
if err != nil {
fmt.Printf("%+v", err)
continue
}
set := models.NewDataSet(s, *users)
sets = append(sets, set)
}

// later, what type of exporter?
ex := export.NewSheetExporter()

document := export.NewDocument("Influencers", sets)
ex.Export(document)
}
55 changes: 55 additions & 0 deletions cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"fmt"
"sync"

"github.com/athletifit/social-network-insights/datastore"
"github.com/athletifit/social-network-insights/models"
"github.com/athletifit/social-network-insights/source"
"github.com/joho/godotenv"
)

// ImportData import sources passed in cmd flags.
func ImportData(sourcesPtr models.ArrayFlags) error {
ch := make(models.UserSetChan)
wg := &sync.WaitGroup{}

var env map[string]string
env, err := godotenv.Read()
if err != nil {
return err
}

for _, s := range sourcesPtr {
src, err := source.NewSource(s, env)
if err != nil {
fmt.Printf("%+v", err)
continue
}

wg.Add(1)
go src.GetUsers(ch, wg)
fmt.Printf("=== %s started === \n", s)
}

// wait that all goroutines have sent the data to close the channel
go func() {
wg.Wait()
close(ch)
}()

dataStore := datastore.NewRedisDataStore()

for userSet := range ch {

fmt.Printf("=== Done with %s ===\n", userSet.Title)
err := dataStore.SaveUsers(userSet)
if err != nil {
fmt.Printf("%+v", err)
}
}

fmt.Println("=== Import finished ===")
return nil
}
18 changes: 18 additions & 0 deletions datastore/datastore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package datastore

import "github.com/athletifit/social-network-insights/models"

type DataStore interface {
LoadUsers(source string) (*models.UserMap, error)
SaveLastTwitterCursor(cursor int64)
SaveUsers(us *models.UserSet) error
}

func NewDataStore(store string) DataStore {
switch store {
case "redis":
return NewRedisDataStore()
}

return nil
}
Loading

0 comments on commit 3de90ab

Please sign in to comment.