Skip to content

Commit

Permalink
Merge pull request #4 from graniet/version-beta
Browse files Browse the repository at this point in the history
Version beta
  • Loading branch information
graniet committed Apr 28, 2019
2 parents 17cf61b + 05bf01e commit 0d45b1f
Show file tree
Hide file tree
Showing 16 changed files with 560 additions and 15 deletions.
9 changes: 7 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ DB_PASS=

OPERATIVE_HISTORY="/tmp/operative_framework.tmp"

INSTAGRAM_LOGIN=Usern4m3
INSTAGRAM_PASSWORD=P4ssw0rd
INSTAGRAM_LOGIN=
INSTAGRAM_PASSWORD=

TWITTER_CONSUMER=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Config struct{
Database DataBase
Common Common
Instagram Network
Twitter Network
}

type Network struct{
Expand Down
5 changes: 5 additions & 0 deletions config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func ParseConfig() (Config, error){
conf.Instagram.Login = os.Getenv("INSTAGRAM_LOGIN")
conf.Instagram.Password = os.Getenv("INSTAGRAM_PASSWORD")

conf.Twitter.Api.Key = os.Getenv("TWITTER_CONSUMER_SECRET")
conf.Twitter.Login = os.Getenv("TWITTER_CONSUMER")
conf.Twitter.Password = os.Getenv("TWITTER_ACCESS_TOKEN")
conf.Twitter.Api.SKey = os.Getenv("TWITTER_ACCESS_TOKEN_SECRET")

conf.Api.Host = os.Getenv("API_HOST")
conf.Api.Port = os.Getenv("API_PORT")
conf.Api.Verbose = os.Getenv("API_VERBOSE")
Expand Down
26 changes: 26 additions & 0 deletions engine/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/graniet/go-pretty/table"
"github.com/graniet/operative-framework/api"
"github.com/graniet/operative-framework/session"
"github.com/joho/godotenv"
"github.com/labstack/gommon/color"
"os"
)
Expand All @@ -16,10 +17,35 @@ func CommandBase(line string, s *session.Session) bool{
} else if line== "info api"{
ViewApiInformation(s)
return true
} else if line == "env"{
viewEnvironment(s)
return true
} else if line == "clear"{
s.ClearScreen()
return true
}
return false
}

func viewEnvironment(s *session.Session){
t := s.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"Name",
"Value",
})
mp, err := godotenv.Read(".env")
if err == nil{
for name, value := range mp{
t.AppendRow(table.Row{
name,
value,
})
}
}
s.Stream.Render(t)
}

func ViewInformation(s *session.Session){
t := s.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
Expand Down
2 changes: 2 additions & 0 deletions filters/filters.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filters

import (
"github.com/graniet/operative-framework/filters/follower_to_screenName"
"github.com/graniet/operative-framework/filters/phone_to_instagram"
"github.com/graniet/operative-framework/filters/say_hello"
"github.com/graniet/operative-framework/session"
Expand All @@ -9,4 +10,5 @@ import (
func LoadFilters(s *session.Session){
s.Filters = append(s.Filters, say_hello.PushSayHelloFilter(s))
s.Filters = append(s.Filters, phone_to_instagram.PushPhoneToInstagramFilter(s))
s.Filters = append(s.Filters, follower_to_screenName.PushFollowerScreenNameFilter(s))
}
61 changes: 61 additions & 0 deletions filters/follower_to_screenName/follower_to_screenname.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package follower_to_screenName

import (
"github.com/ChimeraCoder/anaconda"
"github.com/graniet/go-pretty/table"
"github.com/graniet/operative-framework/session"
"net/url"
"os"
"strconv"
)

type FollowerScreenName struct{
session.SessionFilter
Sess *session.Session
}

func PushFollowerScreenNameFilter(s *session.Session) *FollowerScreenName{
mod := FollowerScreenName{
Sess: s,
}
mod.AddModule("twitter_followers")
return &mod
}

func (filter *FollowerScreenName) Name() string{
return "follower_to_screen"
}

func (filter *FollowerScreenName) Description() string{
return "Find screen name from twitter ID list"
}

func (filter *FollowerScreenName) Author() string{
return "Tristan Granier"
}

func (filter *FollowerScreenName) Start(mod session.Module){
api := anaconda.NewTwitterApiWithCredentials(filter.Sess.Config.Twitter.Password, filter.Sess.Config.Twitter.Api.SKey, filter.Sess.Config.Twitter.Login, filter.Sess.Config.Twitter.Api.Key)
v := url.Values{}

t := filter.Sess.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"id",
"screen_name",
})
for _, id := range mod.GetResults(){
id64, err := strconv.ParseInt(id, 10, 64)
if err == nil {
user, errU := api.GetUsersShowById(id64,v)
if errU == nil{
t.AppendRow(table.Row{
id,
user.ScreenName,

})
}
}
}
filter.Sess.Stream.Render(t)
}
36 changes: 35 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"bufio"
"fmt"
"github.com/akamensky/argparse"
"github.com/chzyer/readline"
"github.com/fatih/color"
"github.com/graniet/operative-framework/api"
"github.com/graniet/operative-framework/engine"
"github.com/graniet/operative-framework/session"
"github.com/joho/godotenv"
"github.com/fatih/color"
"io"
"os"
"strings"
Expand Down Expand Up @@ -45,6 +46,16 @@ func main(){
Help: "Print help",
})

scripts := parser.String("f", "opf", &argparse.Options{
Required: false,
Help: "Run script before prompt starting",
})

quiet := parser.Flag("q", "quiet", &argparse.Options{
Required: false,
Help: "Don't prompt operative shell",
})

err = parser.Parse(os.Args)
if err != nil{
fmt.Print(parser.Usage(err))
Expand Down Expand Up @@ -76,6 +87,28 @@ func main(){
}
}

if *scripts != ""{
file, err := os.Open(*scripts)
defer file.Close()

if err != nil {
fmt.Println(err.Error())
return
}

fscanner := bufio.NewScanner(file)
for fscanner.Scan() {
line := strings.TrimSpace(fscanner.Text())
if !strings.Contains(line, "//"){
sess.ParseCommand(line)
}
}
}

if *quiet{
return
}

if *verbose{
sess.Stream.Verbose = false
} else{
Expand Down Expand Up @@ -104,6 +137,7 @@ func main(){

line = strings.TrimSpace(line)
if line == "api run"{
sess.Stream.Success("API Rest as been started at http://" + sess.Config.Api.Host + ":" + sess.Config.Api.Port)
go apiRest.Start()
sess.Information.SetApi(true)
} else if line == "api stop"{
Expand Down
61 changes: 61 additions & 0 deletions modules/diagram/diagram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package diagram

import (
"fmt"
"github.com/awalterschulze/gographviz"
"github.com/graniet/operative-framework/session"
)

type DiagramModule struct{
session.SessionModule
sess *session.Session
Stream *session.Stream
}

func PushDiagramModuleRetrieval(s *session.Session) *DiagramModule{
mod := DiagramModule{
sess: s,
Stream: &s.Stream,
}
return &mod
}

func (module *DiagramModule) Name() string{
return "diagram"
}

func (module *DiagramModule) Author() string{
return "Tristan Granier"
}

func (module *DiagramModule) Description() string{
return "Generate a diagram of project"
}

func (module *DiagramModule) GetType() string{
return ""
}

func (module *DiagramModule) GetInformation() session.ModuleInformation{
information := session.ModuleInformation{
Name: module.Name(),
Description: module.Description(),
Author: module.Author(),
Type: module.GetType(),
Parameters: module.Parameters,
}
return information
}

func (module *DiagramModule) Start(){
graphAst, _ := gographviz.ParseString(`digraph Project {}`)
graph := gographviz.NewGraph()
if err := gographviz.Analyse(graphAst, graph); err != nil {
panic(err)
}
_ = graph.AddNode("Project", "a", nil)
_ = graph.AddNode("Project", "b", nil)
_ = graph.AddEdge("a", "b", true, nil)
output := graph.String()
fmt.Println(output)
}
2 changes: 2 additions & 0 deletions modules/module_base/session_help/session_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func (module *HelpModule) Start(){
t.AppendRows([]table.Row{
{"info session", "Print current session information"},
{"info api", "Print api rest endpoints information"},
{"env", "Print environment variable"},
{"help", "Print help information"},
{"clear", "Clear current screen"},
{"api <run/stop>", "(Run/Stop) restful API"},
})
module.sess.Stream.Render(t)
Expand Down
4 changes: 4 additions & 0 deletions modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/graniet/operative-framework/modules/module_base/session_help"
"github.com/graniet/operative-framework/modules/module_base/session_stream"
"github.com/graniet/operative-framework/modules/phone_generator"
"github.com/graniet/operative-framework/modules/twitter"
"github.com/graniet/operative-framework/modules/viewdns_search"
"github.com/graniet/operative-framework/modules/whatsapp"
"github.com/graniet/operative-framework/session"
Expand All @@ -25,8 +26,11 @@ func LoadModules(s *session.Session){
s.Modules = append(s.Modules, phone_generator.PushPhoneGeneratorModule(s))
s.Modules = append(s.Modules, whatsapp.PushWhatsappExtractorModule(s))
s.Modules = append(s.Modules, instagram.PushInstagramFollowersModule(s))
s.Modules = append(s.Modules, twitter.PushTwitterFollowerModule(s))
s.Modules = append(s.Modules, twitter.PushTwitterRetweetModule(s))

for _, mod := range s.Modules{
s.PushType(mod.GetType())
mod.CreateNewParam("FILTER", "Use module filter after execution", "",false, session.STRING)
}
}

0 comments on commit 0d45b1f

Please sign in to comment.