コード例 #1
0
ファイル: comment.py プロジェクト: saiashirwad/sem
 def delete_comment(comment_id):
     try:
         query = '''
         match (u:User)-[c:COMMENTED_ON]-(p:Post)
         where c.id = {}
         delete c
         '''
         graph.run(query)
         return True
     except Exception as e:
         return False
コード例 #2
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def delete_post(post_id):

        try:

            query = '''
            match (p:Post)
            where p.id={}
            del p
            '''.format(post_id)

            graph.run(query)

            return True

        except Exception as e:

            print(e)
コード例 #3
0
ファイル: comment.py プロジェクト: saiashirwad/sem
    def create(self):

        query = '''
        match (u:User), (p:Post)
        where u.id={} and p.id={}
        create (u)-[c:COMMENTED_ON {{text: '{}', id: {} }}]->(p)
        return c
        '''.format(self.user_id, self.post_id, self.text, self.id)

        return graph.run(query)
コード例 #4
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def get_likes(post_id):

        query = '''
        match (u:User)-[:LIKES]-(p:Post) 
        where p.id='{}'
        return count(u)
        '''.format(post_id)

        result = graph.run(query)

        return result.data()[0]['count(u)']
コード例 #5
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def find_by_id(post_id):

        query = '''
        match (p:Post)
        where p.id={}
        return p
        '''.format(post_id)

        result = graph.run(query)

        return result.data()[0]['p']
コード例 #6
0
ファイル: user.py プロジェクト: saiashirwad/sem
    def get_posts_by_user(username):

        query = '''
        match (u:User)-[:POSTED]->(p:Post)
        where u.name='{}'
        return p
        '''.format(username)

        result = graph.run(query)

        return result.data()
コード例 #7
0
ファイル: user.py プロジェクト: saiashirwad/sem
    def get_friends(self):

        query = '''
        match (u1:User)-[:FRIENDS_WITH]-(u2:User)
        where u1.username='******'
        return u2
        '''.format(self.username)

        result = graph.run(query)

        return [User.neo4j_to_user(nuser) for nuser in result.data()]
コード例 #8
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def get_post_likers(self):

        query = '''
        match (u:User)-[:LIKES]->(p:Post)
        where p.id='{}'
        return u
        '''.format(self.id)

        result = graph.run(query)

        return [
            '{} {}'.format(i['firstname'], i['lastname']) for i in result()
        ]
コード例 #9
0
ファイル: user.py プロジェクト: saiashirwad/sem
    def friends_with(self, username):
        query = '''
        match (u1:User)-[rel]-(u2:User) 
        where u1.username='******'and u2.username='******' 
        return type(rel) as type
        '''.format(self.username, username)

        result = graph.run(query)

        if result.data()[0]['type'] == 'FRIENDS_WITH':
            return True

        return False
コード例 #10
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def update_post(self, text):

        try:

            query = '''
            match (p:Post)
            where p.id='{}'
            set p.text='{}'
            return p
            '''.format(self.id, text)

            result = graph.run(query)

            return Post.neo4j_to_post(result.data())

        except Exception as e:
            return False
コード例 #11
0
ファイル: post.py プロジェクト: saiashirwad/sem
    def get_post_comments(post_id):

        try:
            query = '''
            match (u:User)-[c:COMMENTED_ON]->(p:Post)
            where p.id={}
            return u.username as creator, c.text as text
            '''.format(post_id)

            print(query)

            result = graph.run(query)

            return result.data()

        except Exception as e:
            print(e)

            return None
コード例 #12
0
ファイル: run.py プロジェクト: HaideiGV/parser
from graph import graph
graph.run(debug=True)