mirror of
https://github.com/arnaucube/twitterDM-to-matrix.git
synced 2026-02-07 03:36:47 +01:00
added a little of username anonymization
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,3 +27,4 @@ _testmain.go
|
|||||||
twitterConfig.json
|
twitterConfig.json
|
||||||
matrixConfig.json
|
matrixConfig.json
|
||||||
temp
|
temp
|
||||||
|
*.txt
|
||||||
25
dataUtils.go
Normal file
25
dataUtils.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dateToHour(date string) string {
|
||||||
|
dateSplit := strings.Split(date, " ")
|
||||||
|
time := dateSplit[3]
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
func getSecFromDate(date string) string {
|
||||||
|
//Fri Apr 28 17:25:22 +0000 2017
|
||||||
|
dateSplit := strings.Split(date, " ")
|
||||||
|
time := dateSplit[3]
|
||||||
|
sec := strings.Split(time, ":")[2]
|
||||||
|
return sec
|
||||||
|
}
|
||||||
|
func anonymousName(originalName string, date string) string {
|
||||||
|
s := strings.Split(originalName, "")
|
||||||
|
//first letter and the last-1 (prelast / penúltima) letter + seconds
|
||||||
|
generatedName := s[0] + s[len(s)-2] + strconv.Itoa(len(s))
|
||||||
|
return generatedName
|
||||||
|
}
|
||||||
@@ -62,10 +62,14 @@ func loginMatrix() {
|
|||||||
func matrixSendMsg(senderScreenName string, message string, createdAt string) {
|
func matrixSendMsg(senderScreenName string, message string, createdAt string) {
|
||||||
txnId := strconv.Itoa(rand.Int())
|
txnId := strconv.Itoa(rand.Int())
|
||||||
c.Green(txnId)
|
c.Green(txnId)
|
||||||
|
|
||||||
|
anonName := anonymousName(senderScreenName, createdAt)
|
||||||
|
hour := dateToHour(createdAt)
|
||||||
|
|
||||||
url := matrixConfig.Server + "/_matrix/client/r0/rooms/" + matrixConfig.RoomId + "/send/m.room.message/" + txnId + "?access_token=" + matrixToken.AccessToken
|
url := matrixConfig.Server + "/_matrix/client/r0/rooms/" + matrixConfig.RoomId + "/send/m.room.message/" + txnId + "?access_token=" + matrixToken.AccessToken
|
||||||
jsonStr := `{
|
jsonStr := `{
|
||||||
"body":"[NEW DM] - at ` + createdAt + `\n@` + senderScreenName + `: ` + message + `",
|
"body":"[NEW DM] - at ` + hour + `h\n@` + anonName + `: ` + message + `",
|
||||||
"msgtype":"m.text"
|
"msgtype":"m.notice"
|
||||||
}`
|
}`
|
||||||
b := strings.NewReader(jsonStr)
|
b := strings.NewReader(jsonStr)
|
||||||
req, _ := http.NewRequest("PUT", url, b)
|
req, _ := http.NewRequest("PUT", url, b)
|
||||||
|
|||||||
Reference in New Issue
Block a user