Created
October 29, 2011 01:20
-
-
Save tomykaira/1323957 to your computer and use it in GitHub Desktop.
save your followers in neo4j
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns friends-relationship-twitter.core | |
(:require [borneo.core :as neo] | |
[oauth.client :as oauth])) | |
(def oauth-consumer (oauth/make-consumer "KEY" | |
"SECRET" | |
"https://api.twitter.com/oauth/request_token" | |
"https://api.twitter.com/oauth/access_token" | |
"https://api.twitter.com/oauth/authorize" | |
:hmac-sha1)) | |
(neo/with-db! "twitter-db" | |
(defn find-node-with-twitter-id [id] | |
(first (filter #(= (try | |
(.getProperty % "id") | |
(catch org.neo4j.graphdb.NotFoundException null)) | |
id) (neo/all-nodes)))) | |
(defn find-or-create [from id] | |
(let [node (find-node-with-twitter-id id) | |
rels (if node (neo/rels node :follower :in))] | |
(if node | |
(when-not (some #(= from (.getStartNode %)) rels) | |
(neo/create-rel! from :follower node)) | |
(neo/create-child! from :follower {:id id})))) | |
(let [me (or (find-node-with-twitter-id YOUR_ID) | |
(neo/create-child! :user {:screen_name "YOUR_SCREEN_NAME" | |
:id YOUR_ID}))] | |
;; 正格評価しないと error: java.lang.IllegalStateException?: Closed id generator | |
(doall (map #(find-or-create me %) (twitter/followers-of-name "YOUR_SCREEN_NAME"))) | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject friends-relationship-twitter "1.0.0-SNAPSHOT" | |
:description "Crawl the friend-follower relationship with Twitter api and save them into Neo4j" | |
:dependencies [[org.clojure/clojure "1.2.1"] | |
[borneo "0.3.0"] | |
[clojure-twitter "1.2.5"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment