-
Notifications
You must be signed in to change notification settings - Fork 0
/
downloadAllInfo.py
142 lines (91 loc) · 3.26 KB
/
downloadAllInfo.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''
Created on May 12, 2012
@author: njordan
'''
from pymongo import Connection
import fbMongo
print "This script will insert all your friends stuff into mongo collections"
#connect to mongodb
connection = Connection("localhost", 27017).facebook
connection.likes.drop()
connection.athletes.drop()
connection.friends.drop()
connection.sports.drop()
connection.teams.drop()
#for every user whos authenticated, get their ID's
for x in connection.accessTokens.find():
userID = x["userId"]
accessToken = x["token"]
#get all their friends
friends = fbMongo.getFacebookObject(accessToken, "me", "friends")
#for every friend they have
for y in friends:
#get their ID
friendId = y["id"]
#get their music
likes = fbMongo.getFacebookObject(accessToken, friendId , "likes")
try:
#insert their likes
for z in likes:
likeId = z["id"]
likeName = z["name"]
likeCategory = z["category"]
connection.likes.insert( { "id" : likeId , "name" : likeName , "category" : likeCategory , "userId" : friendId } )
except KeyError:
None
friend = fbMongo.getFacebookObject(accessToken, friendId , "")
try:
for z in friend["sports"]:
z["userId"] = friendId
connection.sports.insert( z )
except KeyError:
None
try:
for z in friend["favorite_teams"]:
z["userId"] = friendId
connection.teams.insert( z )
except KeyError:
None
try:
for z in friend["favorite_athletes"]:
z["userId"] = friendId
connection.athletes.insert( z )
except KeyError:
None
data = { "id" : friendId }
#gender
try:
data["gender"] = friend["gender"]
except KeyError:
None
#interested in
try:
data["interested_in"] = friend["interested_in"]
except KeyError:
None
#interested in
try:
data["birthday"] = friend["birthday"]
except KeyError:
None
#interested in
try:
data["political"] = friend["political"]
except KeyError:
None
#location
try:
data["location"] = friend["location"]["name"]
except KeyError:
None
#hometown
try:
data["hometown"] = friend["hometown"]["name"]
except KeyError:
None
#relationship status
try:
data["relationship_status"] = friend["relationship_status"]
except KeyError:
None
connection.friends.insert( data )