|
@@ -0,0 +1,35 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "bufio"
|
|
|
+ "encoding/csv"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "log"
|
|
|
+ "os"
|
|
|
+
|
|
|
+ "github.com/gomodule/redigo/redis"
|
|
|
+ rg "github.com/maguec/redisgraph-go"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ csvFile, _ := os.Open("subreddit_members")
|
|
|
+ reader := csv.NewReader(bufio.NewReader(csvFile))
|
|
|
+ reader.Comma = '\t'
|
|
|
+ reader.LazyQuotes = true
|
|
|
+ conn, _ := redis.Dial("tcp", "localhost:6379")
|
|
|
+ graph := rg.Graph{}.New("Reddit", conn)
|
|
|
+ for {
|
|
|
+ line, error := reader.Read()
|
|
|
+ if error == io.EOF {
|
|
|
+ break
|
|
|
+ } else if error != nil {
|
|
|
+ log.Print(error)
|
|
|
+ } else {
|
|
|
+ query := fmt.Sprintf("MATCH (s:SubReddit {RedditId:'%s'}), (u:User {RedditId:'%s'}) CREATE (u)-[d:SUBSCRIBE]->(s)", line[0], line[1])
|
|
|
+ graph.Query(query)
|
|
|
+ graph.Flush()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn.Close()
|
|
|
+}
|