Compare commits
No commits in common. "9d25ec90430266bba44b1836654c7119db52c0cd" and "7b1daeec403e07b4ec7ec4a4e3836b35795595bd" have entirely different histories.
9d25ec9043
...
7b1daeec40
5 changed files with 26 additions and 63 deletions
|
@ -1,4 +1,4 @@
|
||||||
# [Discord Chat Exporter](https://github.com/Tyrrrz/DiscordChatExporter) csv parsers
|
# Discord Chat Exporter csv parsers
|
||||||
|
|
||||||
<sub> Now with a much faster version written in go! </sub>
|
<sub> Now with a much faster version written in go! </sub>
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
To run the go versions all you need to do is download the executable for your platform and run it from the terminal/powershell:
|
To run the go versions all you need to do is download the executable for your platform and run it from the terminal/powershell:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./ParseIDs[.exe] -i [Path to folder/file] -o [Path to output .csv (Defaults to ./out.csv)]
|
./IdParser[.exe] -i [Path to folder/file] -o [Path to output .csv (Defaults to ./out.csv)]
|
||||||
```
|
```
|
||||||
|
|
||||||
Use the same output between multiple runs works and takes into account old data to ensure no dupes
|
Use the same output between multiple runs works and takes into account old data to ensure no dupes
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Variables used for command line parameters
|
// Variables used for command line parameters
|
||||||
var (
|
var (
|
||||||
CsvInput string
|
CsvInput string
|
||||||
CsvOutput string
|
CsvOutput string
|
||||||
unique_old []string
|
unique_old []string
|
||||||
unique_name []string
|
unique_ids []string
|
||||||
unique_ids []string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -31,8 +27,7 @@ func init() {
|
||||||
|
|
||||||
// struct for getting just user ID out of csv file
|
// struct for getting just user ID out of csv file
|
||||||
type DiscordCSV struct {
|
type DiscordCSV struct {
|
||||||
UserID string
|
UserID string
|
||||||
Username string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -61,17 +56,9 @@ func main() {
|
||||||
// For each file in folder
|
// For each file in folder
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
// file is not a directory so process it's full path
|
process(CsvInput + file.Name())
|
||||||
// check if windows or linux
|
|
||||||
if strings.Contains(CsvInput, "\\") {
|
|
||||||
// windows
|
|
||||||
process(CsvInput + "\\" + file.Name())
|
|
||||||
} else {
|
|
||||||
// linux
|
|
||||||
process(CsvInput + "/" + file.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,21 +77,16 @@ func process(CsvPath string) {
|
||||||
// Read CSV file
|
// Read CSV file
|
||||||
lines, err := ReadCsv(CsvOutput)
|
lines, err := ReadCsv(CsvOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// Loop through lines & turn into object
|
||||||
// Loop through lines & add to DiscordIDs list
|
for _, line := range lines {
|
||||||
for i, _ := range lines {
|
|
||||||
|
|
||||||
data := DiscordCSV{
|
data := DiscordCSV{
|
||||||
UserID: lines[i][0],
|
UserID: line[0],
|
||||||
Username: lines[i][1],
|
|
||||||
}
|
|
||||||
if !contains(unique_old, data.UserID) {
|
|
||||||
unique_old = append(unique_old, data.UserID)
|
|
||||||
unique_name = append(unique_name, data.Username)
|
|
||||||
}
|
}
|
||||||
|
unique_old = append(unique_old, data.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteCSV(CsvPath)
|
WriteCSV(CsvPath)
|
||||||
|
|
||||||
} else if errors.Is(err, os.ErrNotExist) {
|
} else if errors.Is(err, os.ErrNotExist) {
|
||||||
|
@ -130,7 +112,6 @@ func process(CsvPath string) {
|
||||||
func WriteCSV(InFile string) {
|
func WriteCSV(InFile string) {
|
||||||
// Create DiscordIDs list
|
// Create DiscordIDs list
|
||||||
var DiscordIDs []string
|
var DiscordIDs []string
|
||||||
var DiscordNames []string
|
|
||||||
|
|
||||||
// Read CSV file
|
// Read CSV file
|
||||||
lines, err := ReadCsv(InFile)
|
lines, err := ReadCsv(InFile)
|
||||||
|
@ -141,23 +122,20 @@ func WriteCSV(InFile string) {
|
||||||
OutFile, err := os.OpenFile(CsvOutput, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
OutFile, err := os.OpenFile(CsvOutput, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
|
|
||||||
// Loop through lines & add to DiscordIDs list
|
// Loop through lines & add to DiscordIDs list
|
||||||
for i, _ := range lines {
|
for _, line := range lines {
|
||||||
|
|
||||||
data := DiscordCSV{
|
data := DiscordCSV{
|
||||||
UserID: lines[i][0],
|
UserID: line[0],
|
||||||
Username: lines[i][1],
|
|
||||||
}
|
}
|
||||||
if !contains(DiscordIDs, data.UserID) {
|
if !contains(DiscordIDs, data.UserID) {
|
||||||
DiscordIDs = append(DiscordIDs, data.UserID)
|
DiscordIDs = append(DiscordIDs, data.UserID)
|
||||||
DiscordNames = append(DiscordNames, data.Username)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if ID is already in list
|
// Checks if ID is already in list
|
||||||
// if it isnt then it gets writen to list
|
// if it isnt then it gets writen to list
|
||||||
for i, ID := range DiscordIDs {
|
for _, ID := range DiscordIDs {
|
||||||
if !contains(unique_old, ID) {
|
if !contains(unique_old, ID) {
|
||||||
OutFile.WriteString(ID + "," + DiscordNames[i] + "\n")
|
OutFile.WriteString(ID + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,21 +149,8 @@ func ReadCsv(filename string) ([][]string, error) {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
io.Copy(&buf, f)
|
|
||||||
|
|
||||||
x := string(buf.Bytes())
|
|
||||||
|
|
||||||
strings.ReplaceAll(x, "\r\n", "\n")
|
|
||||||
|
|
||||||
strings.ReplaceAll(x, "\r\n", " ")
|
|
||||||
|
|
||||||
reader := csv.NewReader(strings.NewReader(x))
|
|
||||||
|
|
||||||
reader.ReuseRecord = true
|
|
||||||
|
|
||||||
// Read File into a Variable
|
// Read File into a Variable
|
||||||
lines, err := reader.ReadAll()
|
lines, err := csv.NewReader(f).ReadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [][]string{}, err
|
return [][]string{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
package="./IdParser.go"
|
package="./User ID Praser/IdParser.go"
|
||||||
|
|
||||||
package_split=(${package//\// })
|
package_split=(${package//\// })
|
||||||
package_name="IdParser"
|
package_name="IdParser"
|
||||||
|
@ -15,11 +15,11 @@ do
|
||||||
GOOS=${platform_split[0]}
|
GOOS=${platform_split[0]}
|
||||||
GOARCH=${platform_split[1]}
|
GOARCH=${platform_split[1]}
|
||||||
output_name=$package_name'-'$GOOS'-'$GOARCH
|
output_name=$package_name'-'$GOOS'-'$GOARCH
|
||||||
if [ "$GOOS" = "windows" ]; then
|
if [ $GOOS = "windows" ]; then
|
||||||
output_name+='.exe'
|
output_name+='.exe'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
env GOOS="$GOOS" GOARCH=$GOARCH go build -o "./build/$output_name" $package
|
env GOOS=$GOOS GOARCH=$GOARCH go build -o ./User ID Praser/build/$output_name $package
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo 'An error has occurred! Aborting the script execution...'
|
echo 'An error has occurred! Aborting the script execution...'
|
||||||
exit 1
|
exit 1
|
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
package="./LocateID.go"
|
package="./Locate ID/LocateID.go"
|
||||||
|
|
||||||
package_split=(${package//\// })
|
package_split=(${package//\// })
|
||||||
package_name="LocateID"
|
package_name="LocateID"
|
||||||
|
@ -16,11 +15,11 @@ do
|
||||||
GOOS=${platform_split[0]}
|
GOOS=${platform_split[0]}
|
||||||
GOARCH=${platform_split[1]}
|
GOARCH=${platform_split[1]}
|
||||||
output_name=$package_name'-'$GOOS'-'$GOARCH
|
output_name=$package_name'-'$GOOS'-'$GOARCH
|
||||||
if [ "$GOOS" = "windows" ]; then
|
if [ $GOOS = "windows" ]; then
|
||||||
output_name+='.exe'
|
output_name+='.exe'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
env GOOS="$GOOS" GOARCH="$GOARCH" go build -o ./build/$output_name $package
|
env GOOS=$GOOS GOARCH=$GOARCH go build -o "./Locate ID/build/$output_name" $package
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo 'An error has occurred! Aborting the script execution...'
|
echo 'An error has occurred! Aborting the script execution...'
|
||||||
exit 1
|
exit 1
|
|
@ -1,2 +1 @@
|
||||||
pandas~=1.3.1
|
pandas~=1.3.1
|
||||||
numpy>=1.22.2 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
||||||
|
|
Reference in a new issue