Пример #1
0
 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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
from graph import graph
graph.run(debug=True)