mirror of
https://github.com/arnaucube/flock-botnet.git
synced 2026-02-06 19:16:39 +01:00
added progress bar on generting markov chains
This commit is contained in:
34
main.go
34
main.go
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,8 +16,14 @@ func main() {
|
|||||||
c.Purple("https://github.com/arnaucode/twFlock")
|
c.Purple("https://github.com/arnaucode/twFlock")
|
||||||
fmt.Println("version " + version)
|
fmt.Println("version " + version)
|
||||||
fmt.Println("Reading flockConfig.json file")
|
fmt.Println("Reading flockConfig.json file")
|
||||||
//flock := readConfigTokensAndConnect()
|
flock := readConfigTokensAndConnect()
|
||||||
var flock Flock
|
|
||||||
|
c.Yellow("generating markov chains (may take some seconds)")
|
||||||
|
text, _ := readTxt("text.txt")
|
||||||
|
states := markov.train(text)
|
||||||
|
c.Green("markov chains generated")
|
||||||
|
|
||||||
|
//var flock Flock
|
||||||
fmt.Println("---------------")
|
fmt.Println("---------------")
|
||||||
newcommand := bufio.NewReader(os.Stdin)
|
newcommand := bufio.NewReader(os.Stdin)
|
||||||
fmt.Print("Please select command number")
|
fmt.Print("Please select command number")
|
||||||
@@ -40,28 +45,7 @@ option to select: `
|
|||||||
break
|
break
|
||||||
case "2":
|
case "2":
|
||||||
fmt.Println("selected 2 - Markov")
|
fmt.Println("selected 2 - Markov")
|
||||||
|
optionTweetMarkov(states)
|
||||||
fmt.Print("entry the first word: ")
|
|
||||||
newcommand := bufio.NewReader(os.Stdin)
|
|
||||||
firstWord, _ := newcommand.ReadString('\n')
|
|
||||||
firstWord = strings.TrimSpace(firstWord)
|
|
||||||
fmt.Print("first word: ")
|
|
||||||
c.Purple(firstWord)
|
|
||||||
|
|
||||||
c.Red("how many words you want on the text?")
|
|
||||||
newcommand = bufio.NewReader(os.Stdin)
|
|
||||||
answer, _ := newcommand.ReadString('\n')
|
|
||||||
answer = strings.TrimSpace(answer)
|
|
||||||
fmt.Print("Number of words on text to generate: ")
|
|
||||||
c.Purple(answer)
|
|
||||||
count, err := strconv.Atoi(answer)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("incorrect entry, need a positive number")
|
|
||||||
}
|
|
||||||
|
|
||||||
states := markov.train("the", "text.txt")
|
|
||||||
generatedText := markov.generateText(states, firstWord, count)
|
|
||||||
c.Green(generatedText)
|
|
||||||
break
|
break
|
||||||
case "0":
|
case "0":
|
||||||
fmt.Println("selected 0 - exit script")
|
fmt.Println("selected 0 - exit script")
|
||||||
|
|||||||
31
markov.go
31
markov.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,11 +9,6 @@ import (
|
|||||||
|
|
||||||
type Markov struct{}
|
type Markov struct{}
|
||||||
|
|
||||||
/*type NextState struct {
|
|
||||||
Word string
|
|
||||||
Count int
|
|
||||||
Prob float64
|
|
||||||
}*/
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Word string
|
Word string
|
||||||
Count int
|
Count int
|
||||||
@@ -24,6 +18,17 @@ type State struct {
|
|||||||
|
|
||||||
var markov Markov
|
var markov Markov
|
||||||
|
|
||||||
|
func printLoading(n int, total int) {
|
||||||
|
var bar []string
|
||||||
|
tantPerFourty := int((float64(n) / float64(total)) * 40)
|
||||||
|
tantPerCent := int((float64(n) / float64(total)) * 100)
|
||||||
|
for i := 0; i < tantPerFourty; i++ {
|
||||||
|
bar = append(bar, "█")
|
||||||
|
}
|
||||||
|
progressBar := strings.Join(bar, "")
|
||||||
|
fmt.Printf("\r " + progressBar + " - " + strconv.Itoa(tantPerCent) + "%")
|
||||||
|
}
|
||||||
|
|
||||||
func addWordToStates(states []State, word string) ([]State, int) {
|
func addWordToStates(states []State, word string) ([]State, int) {
|
||||||
iState := -1
|
iState := -1
|
||||||
for i := 0; i < len(states); i++ {
|
for i := 0; i < len(states); i++ {
|
||||||
@@ -54,6 +59,8 @@ func calcMarkovStates(words []string) []State {
|
|||||||
if iState < len(words) {
|
if iState < len(words) {
|
||||||
states[iState].NextStates, _ = addWordToStates(states[iState].NextStates, words[i+1])
|
states[iState].NextStates, _ = addWordToStates(states[iState].NextStates, words[i+1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printLoading(i, len(words))
|
||||||
}
|
}
|
||||||
|
|
||||||
//count prob
|
//count prob
|
||||||
@@ -74,18 +81,8 @@ func textToWords(text string) []string {
|
|||||||
return words
|
return words
|
||||||
}
|
}
|
||||||
|
|
||||||
func readText(path string) (string, error) {
|
func (markov Markov) train(text string) []State {
|
||||||
data, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
//Do something
|
|
||||||
}
|
|
||||||
dataClean := strings.Replace(string(data), "\n", " ", -1)
|
|
||||||
content := string(dataClean)
|
|
||||||
return content, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (markov Markov) train(firstWord string, path string) []State {
|
|
||||||
text, _ := readText(path)
|
|
||||||
words := textToWords(text)
|
words := textToWords(text)
|
||||||
states := calcMarkovStates(words)
|
states := calcMarkovStates(words)
|
||||||
//fmt.Println(states)
|
//fmt.Println(states)
|
||||||
|
|||||||
47
optionTweetMarkov.go
Normal file
47
optionTweetMarkov.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func optionTweetMarkov(states []State) {
|
||||||
|
|
||||||
|
fmt.Print("entry the first word: ")
|
||||||
|
newcommand := bufio.NewReader(os.Stdin)
|
||||||
|
firstWord, _ := newcommand.ReadString('\n')
|
||||||
|
firstWord = strings.TrimSpace(firstWord)
|
||||||
|
fmt.Print("first word: ")
|
||||||
|
c.Purple(firstWord)
|
||||||
|
|
||||||
|
c.Red("how many words you want on the text?")
|
||||||
|
newcommand = bufio.NewReader(os.Stdin)
|
||||||
|
answer, _ := newcommand.ReadString('\n')
|
||||||
|
answer = strings.TrimSpace(answer)
|
||||||
|
fmt.Print("Number of words on text to generate: ")
|
||||||
|
c.Purple(answer)
|
||||||
|
count, err := strconv.Atoi(answer)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("incorrect entry, need a positive number")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Red("how many sentences you want to generate?")
|
||||||
|
newcommand = bufio.NewReader(os.Stdin)
|
||||||
|
answer, _ = newcommand.ReadString('\n')
|
||||||
|
answer = strings.TrimSpace(answer)
|
||||||
|
fmt.Print("Number of sentences to generate: ")
|
||||||
|
c.Purple(answer)
|
||||||
|
sentences, err := strconv.Atoi(answer)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("incorrect entry, need a positive number")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("generating text")
|
||||||
|
for i := 0; i < sentences; i++ {
|
||||||
|
generatedText := markov.generateText(states, firstWord, count)
|
||||||
|
c.Green(generatedText)
|
||||||
|
}
|
||||||
|
}
|
||||||
16
readTxt.go
Normal file
16
readTxt.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func readTxt(path string) (string, error) {
|
||||||
|
data, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
//Do something
|
||||||
|
}
|
||||||
|
dataClean := strings.Replace(string(data), "\n", " ", -1)
|
||||||
|
content := string(dataClean)
|
||||||
|
return content, err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user