load_subreddit_relationships.go 730 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "bufio"
  4. "encoding/csv"
  5. "fmt"
  6. "io"
  7. "log"
  8. "os"
  9. "github.com/gomodule/redigo/redis"
  10. rg "github.com/maguec/redisgraph-go"
  11. )
  12. func main() {
  13. csvFile, _ := os.Open("subreddit_members")
  14. reader := csv.NewReader(bufio.NewReader(csvFile))
  15. reader.Comma = '\t'
  16. reader.LazyQuotes = true
  17. for {
  18. line, error := reader.Read()
  19. if error == io.EOF {
  20. break
  21. } else if error != nil {
  22. log.Print(error)
  23. } else {
  24. conn, _ := redis.Dial("tcp", "localhost:6379")
  25. graph := rg.Graph{}.New("Reddit", conn)
  26. query := fmt.Sprintf("MATCH (s:SubReddit {RedditId:'%s'}), (u:User {RedditId:'%s'}) CREATE (u)-[d:SUBSCRIBE]->(s)", line[0], line[1])
  27. graph.Query(query)
  28. graph.Flush()
  29. conn.Close()
  30. }
  31. }
  32. }