-
Notifications
You must be signed in to change notification settings - Fork 0
/
tebdCypherTwitter.py
executable file
·80 lines (72 loc) · 2.04 KB
/
tebdCypherTwitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
neo4jUrl = os.environ.get('NEO4J_URL',"http://localhost:7474/db/data/")
cqlCreateMyUser = """
WITH {json} as us
MERGE (user:UserTwitter {id:us.id})
ON CREATE SET
user.name = us.name,
user.location = us.location,
user.screen_name = us.screen_name,
user.followers_count = us.followers_count,
user.friends_count = us.friends_count
ON MATCH SET
user.name = us.name,
user.location = us.location,
user.screen_name = us.screen_name,
user.followers_count = us.followers_count,
user.friends_count = us.friends_count
"""
cqlFollowers = """
MATCH (:UserTwitter {id:%s})-[:FOLLOWS]->(f:UserTwitter)
RETURN f.id AS id
"""
cqlCreateUsers = """
WITH {json} as dt
UNWIND dt.users as us
MERGE (user:UserTwitter {id:us.id})
ON CREATE SET
user.name = us.name,
user.location = us.location,
user.screen_name = us.screen_name,
user.followers_count = us.followers_count,
user.friends_count = us.friends_count
ON MATCH SET
user.name = us.name,
user.location = us.location,
user.screen_name = us.screen_name,
user.followers_count = us.followers_count,
user.friends_count = us.friends_count
MERGE (me:UserTwitter {id:%s})
WITH me, user
MERGE (me)-[:FOLLOWS]->(user)
"""
cqlUsersTwitter = """
MATCH (f:UserTwitter)
RETURN f.id AS id, f.screen_name AS screen_name
"""
cqlCreateHashtag = """
WITH {createdAt} as created_at, {country} as country, {city} as city, {retweetCount} as retweet_count,
{favoriteCount} as favorite_count, {hashtag} as hashtag, {idUser} as id_user
MERGE (ht:HashtagTwitter {hashtag: hashtag, created_at: created_at})<-[:TWEETED]-(:UserTwitter {id: id_user})
ON CREATE SET
ht.retweet_count = retweet_count,
ht.favorite_count = favorite_count,
ht.city = city,
ht.country = country
ON MATCH SET
ht.retweet_count = retweet_count,
ht.favorite_count = favorite_count
"""
# NOT USED
cqlDeleteAll = """
MATCH (a:UserTwitter)-[b]->(c)
MATCH (d)-[e]->(f:UserTwitter)
MATCH (g:UserTwitter)
DELETE b
DELETE e
DELETE g
"""
cqlMatchAll = """
MATCH (a:UserTwitter)
RETURN a
"""