def get(self, post_type): req = "MATCH (find:post {type: '%s'}) RETURN find" % post_type req += addargs() result = neo4j.query_neo4j(req) posts = [] for record in result: posts.append(record['find'].properties) return makeResponse(posts, 200)
def get(self, author_id): req = "MATCH (author:user {user_id: %d})-[:AUTHORSHIP]->(p:post) RETURN p" % author_id req += addargs() result = neo4j.query_neo4j(req) posts = [] for record in result: posts.append(record['p'].properties) return makeResponse(posts, 200)
def get(self, comment_id): req = "MATCH (c:comment)-[:COMMENTS]->(comment:comment { comment_id: %d}) RETURN c" % comment_id req += addargs() result = neo4j.query_neo4j(req) comments = [] for record in result: comments.append(record['c'].properties) return makeResponse(comments, 200)
def get(self): req = "MATCH (t:tag) RETURN t.tag_id AS tag_id, t.label AS label" req += addargs() result = neo4j.query_neo4j(req) tags = [] for record in result: tags.append({'tag_id': record['tag_id'], "label": record['label']}) return makeResponse(tags, 200)
def get(self, comment_id): req = "MATCH (c:comment {comment_id: %d})<-[:ANNOTATES]-(a:annotation) RETURN a" % comment_id req += addargs() result = neo4j.query_neo4j(req) annots = [] for record in result: annots.append(record['a'].properties) return makeResponse(annots, 200)
def get(self): req = "MATCH (n:user) RETURN n.user_id AS user_id, n.label AS label" req += addargs() result = neo4j.query_neo4j(req) users = [] for record in result: users.append({'user_id': record['user_id'], "label": record['label']}) return makeResponse(users, 200)
def get(self, user_id): req = "MATCH (:user {user_id: %d})-[:AUTHORSHIP]->(a:annotation) RETURN a" % user_id req += addargs() result = neo4j.query_neo4j(req) annots = [] for record in result: annots.append(record['a'].properties) return makeResponse(annots, 200)
def get(self): req = "MATCH (p:post) RETURN p.post_id AS post_id, p.title AS title" req += addargs() result = neo4j.query_neo4j(req) posts = [] for record in result: posts.append({'post_id': record['post_id'], "title": record['title']}) return makeResponse(posts, 200)
def get(self): req = "MATCH (a:annotation)-[:REFERS_TO]->(t:tag) MATCH (a)-[:ANNOTATES]-(x) RETURN a.annotation_id AS annotation_id, a.quote AS quote, t.tag_id AS tag_id, CASE x.post_id WHEN null THEN 'comment' ELSE 'post' END AS entity_type, CASE x.post_id WHEN null THEN x.comment_id ELSE x.post_id END AS entity_id" req += addargs() result = neo4j.query_neo4j(req) annots = [] for record in result: annots.append({'annotation_id': record['annotation_id'], "quote": record['quote'], "tag_id": record['tag_id'], "entity_type": record["entity_type"], "entity_id": record["entity_id"]}) return makeResponse(annots, 200)
def get(self): req = "MATCH (n:post) RETURN n.timestamp AS timestamp ORDER BY timestamp ASC" req += addargs() result = neo4j.query_neo4j(req) posts = [] count = 1 for record in result: posts.append({"count": count, "timestamp": record['timestamp']}) count += 1 return makeResponse(posts, 200)
def get(self, type, min, max): req = "MATCH (n:%s) WHERE n.timestamp >= %d AND n.timestamp <= %d RETURN n.timestamp AS timestamp ORDER BY timestamp ASC" % (type, min, max) req += addargs() result = neo4j.query_neo4j(req) val = [] count = 1 for record in result: val.append({"count": count, "timestamp": record['timestamp']}) count += 1 return makeResponse(val, 200)
def get(self): req = "MATCH (c:comment) RETURN c.comment_id AS comment_id, c.title AS title" req += addargs() result = neo4j.query_neo4j(req) comments = [] for record in result: comments.append({ 'comment_id': record['comment_id'], "title": record['title'] }) return makeResponse(comments, 200)
def get(self): req = "MATCH (a:annotation) RETURN a.annotation_id AS annotation_id, a.quote AS quote" req += addargs() result = neo4j.query_neo4j(req) annots = [] for record in result: annots.append({ 'annotation_id': record['annotation_id'], "quote": record['quote'] }) return makeResponse(annots, 200)
def get(self): req = "MATCH (p:post)<-[:AUTHORSHIP]-(u:user) RETURN p.post_id AS post_id, p.title AS title, p.content AS content, p.timestamp AS timestamp, u.user_id AS user_id" req += addargs() result = neo4j.query_neo4j(req) posts = [] for record in result: fmt_time = datetime.datetime.fromtimestamp( record['timestamp'] / 1000).strftime('%Y-%m-%d %H:%M:%S') posts.append({ 'post_id': record['post_id'], "title": record['title'], "content": record["content"], "timestamp": fmt_time, "user_id": record["user_id"] }) return makeResponse(posts, 200)