Pensieve header: Make a facebook friends graph following ... - Drorbn

cakeexoticInternet και Εφαρμογές Web

13 Δεκ 2013 (πριν από 3 χρόνια και 6 μήνες)

84 εμφανίσεις

Pensieve
header:
Make
a
facebook
friends
graph
following
http://mathematica.stackexchange.com/ques
-
t
i
o
n
s
/
1
1
6
7
3
/
h
o
w
-
t
o
-
p
l
a
y
-
w
i
t
h
-
f
a
c
e
b
o
o
k
-
d
a
t
a
-
i
n
s
i
d
e
-
m
a
t
h
e
m
a
t
i
c
a
.
SetDirectory
@
"
C
:
\\
drorbn
\\
AcademicPensieve
\\
2012
-
10
"
D
;
H
*
Get
friends
name
and
facebook
code
*
L
getFriendsList
@
D
:
=
Rule

Import
@
"
https
:

graph
.
facebook
.
com

me

friends
?
access_token
=
"
<>
token
,
"
JSON
"
D
@
@
1
,
2
,
All
,
All
,
2
D
D
H
*
Get
your
friends
photo
link
and
sex
*
L
8
cName
,
cPhotoLink
,
cSex
,
cCode
<
=
Range
@
4
D
;
getFriendsData
@
fList_
D
:
=
Module
@
8
url
,
query
,
friendsData
,
fListString
<
,
fListString
=
conv2StringList
@
fList
@
@
All
,
1
D
D
D
;
url
=
"
https
:

api
.
facebook
.
com

method

fql
.
query
?
access_token
=
"
<>
token
<>
"
&
query
=
"
;
query
=
url
<>
"
SELECT
uid
,
name
,
sex
,
pic_square
FROM
user
WHERE
uid
in
"
<>
fListString
<>
"
&
format
=
JSON
"
;
query
=
StringReplace
@
query
,
"
"
®
"
%
20
"
D
;
friendsData
=
Import
@
query
,
"
JSON
"
D
@
@
All
,
All
,
-
1
D
D
D
H
*
Get
friends
pairs
connections
*
L
getFriendsPairsPart
@
fList1_
,
fList2_
D
:
=
Module
@
8
url
,
query1
,
friendsPairs
,
friendsStr1
,
firendsStr2
<
,
friendsStr1
=
conv2StringList
@
fList1
D
;
firendsStr2
=
conv2StringList
@
fList2
D
;
url
=
"
https
:

api
.
facebook
.
com

method

fql
.
query
?
access_token
=
"
<>
token
<>
"
&
query
=
"
;
query1
=
url
<>
"
SELECT
uid1
,
uid2
FROM
friend
WHERE
uid1
in
"
<>
friendsStr1
<>
"
and
uid2
in
"
<>
firendsStr2
<>
"
&
format
=
JSON
"
;
query1
=
StringReplace
@
query1
,
"
"
®
"
%
20
"
D
;
friendsPairs
=
Import
@
query1
,
"
JSON
"
D
;
friendsPairs
=
H
Sort


friendsPairs
L

Union
D
getFriendsPairs
@
friendsList_
D
:
=
Module
@
8
groupsComb
,
groupsCompLen
,
maxUsers
=
3
,
friendsPairs
,
i
=
1
<
,
SetSharedVariable
@
i
D
;
groupsComb
=
Partition
@
friendsList
@
@
All
,
1
D
D
,
maxUsers
,
maxUsers
,
1
,
8
<
D
;
groupsComb
=
Subsets
@
groupsComb
,
8
2
<
D
;
groupsCompLen
=
Length
@
groupsComb
D
;
Print
@
"
Extracting
Connections
"
D
;
Print
@
Dynamic

mrtProgressBar
@
i
,
groupsCompLen
D
D
;
friendsPairs
=
Flatten
@
ParallelMap
@
H
i
++
;
getFriendsPairsPart

ð
L
&
,
groupsComb
D
,
1
D
;
friendsPairs
=
UndirectedEdge

friendsPairs
@
@
All
,
All
,
2
D
D
;
friendsPairs
=
Union
@
Sort


friendsPairs
D
;
Print
@
Row

8
"
Connections
number
:
"
,
Length

friendsPairs
<
D
;
friendsPairs
D
H
*
Get
friends
photos
*
L
getFriendsPhotos
@
friendsData_
D
:
=
Module
@
8
append
,
friends
,
photos
,
page
,
i
=
1
,
tabImg
=
8
<
<
,
SetSharedVariable
@
i
D
;
SetSharedVariable
@
tabImg
D
;
Print
@
"
Extracting
user
pictures
:
"
D
;
Print
@
Dynamic

mrtProgressBar
@
i
,
Length
@
friendsData
D
D
D
;
Print
@
Dynamic

GraphicsGrid
@
If
@
Length
@
tabImg
D

0
,
8
8
"
"
<
<
,
Partition
@
tabImg
,
10
,
10
,
1
,
8
<
D
D
,
ImageSize
®
200
D
D
;
append
@
data_Image
D
:
=
Module
@
8
<
,
If
@
Length
@
tabImg
D
>
100
,
tabImg
=
8
<
D
;
AppendTo
@
tabImg
,
data
D
;
data
D
;
H
*
CloseKernels
@
D
;
LaunchKernels
@
8
D
;
*
L
photos
=
ParallelMap
@
H
i
++
;
8
append
@
Import
@
ð
@
@
cPhotoLink
D
D
D
D
,
ToString
@
ð
@
@
cCode
D
D
D
<
L
&
,
friendsData
D
;
Print
@
Row

8
"
Photo
'
s
number
:
"
,
Length
@
photos
D
<
D
;
photos
D
adjustPhotos
@
friendsPhotos_
,
friendsPairs_
D
:
=
Module
@
8
friends
,
photosSel
,
graph
,
page
<
,
graph
=
Graph

friendsPairs
;
friends
=
VertexList

graph
;
page
=
PageRankCentrality
@
graph
,
0.1
D
;
page
=
Rescale
@
page
,
8
0
,
Max
@
page
D
<
,
8
0.1
,
0.9
<
D
;
page
=
Rule

Transpose
@
8
friends
,
page
<
D
;
photosSel
=
Select
@
friendsPhotos
,
MemberQ
@
friends
,
ð
@
@
2
D
D
D
&
D
;
H
ð
@
@
2
D
D
®
Hyperlink
@
Magnify
@
ð
@
@
1
D
D
,
ð
@
@
2
D
D
D

.
page
,
"
http
:

www
.
facebook
.
com

profile
.
php
?
id
=
"
<>
ð
@
@
2
D
D
D
L
&


photosSel
D
H
*
Plot
Facebook
graph
*
L
createGraph
@
friendsPairs_
,
friendsPhotosForVertex_
D
:
=
Module
@
8
g1
,
g2
,
g3
,
label
<
,
g1
=
Graph
@
friendsPairs
,
VertexShape
®
friendsPhotosForVertex
,
VertexSize
®
5
,
EdgeStyle
®
Opacity
@
0
D
D
;
g2
=
Graph
@
friendsPairs
,
VertexSize
®
0
,
EdgeStyle
®
Thickness
@
0.0001
D
D
;
label
=
Graphics
@
8
Style
@
Text
@
"
by
Rodrigo
Murta
\n
www
.
rodrigomurta
.
com
"
D
,
Blue
D
<
,
ImageSize
®
300
D
;
g3
=
Show
@
g2
,
g1
,
label
,
ImageSize
®
1000
D
D
H
*
Execute
code
*
L
createMyFacebookPDF
@
D
:
=
Module
@
8
myFacebookGraph
<
,
SetDirectory
@
NotebookDirectory
@
D
D
;
Print
@
"
Extracting
friends
data
"
D
;
friendsList
=
getFriendsList
@
D
;
H
*
friendsList
=
DeleteCases
@
friendsList
,
"
100000344024829
"
®
_
D
;
*
L
Print
@
friendsList
D
;
friendsData
=
getFriendsData
@
friendsList
D
;
friendsPairs
=
getFriendsPairs
@
friendsList
D
;
friendsPhotos
=
getFriendsPhotos
@
friendsData
D
;
photosForVertice
=
adjustPhotos
@
friendsPhotos
,
friendsPairs
D
;
Print
@
"
Creating
GraphPlot
"
D
;
myFacebookGraph
=
;
2




Untitled-1
createGraph
@
friendsPairs
,
photosForVertice
D
Print
@
"
Creating
PDF
"
D
;
Export
@
"
myFacebookGraph
.
pdf
"
,
myFacebookGraph
D
;
Print
@
"
PDF
Created
!
"
D
;
D

Quiet
H
*
quiet
to
avoid
uni
core
msg
*
L
H
*
Other
Funcitons
*
L
mrtProgressBar
@
var_
,
total_
D
:
=
Row
@
8
ProgressIndicator
@
var
,
8
0
,
total
<
D
,
"
"
,
Row
@
8
NumberForm
@
100.
var

total
,
8
¥
,
2
<
D
,
"
%
"
<
D
,
"
%
"
,
var
<
D
conv2StringList
@
list_
D
:
=
StringReplace
@
ToString
@
list
D
,
8
"
8
"
®
"
H
"
,
"
<
"
®
"
L
"
,
"
"
®
"
"
<
D
Get
facebook
token
from
http://developers.facebook.com/tools/explorer/?method=GET&path=me
and

put
it
below.
token
=
InputString
@
D
;
createMyFacebookPDF
@
D
Untitled-1




3
Extracting
friends
data
8
28123401
®
Lindsey
Shorser
,
502850573
®
Peter
Crooks
,
508038243
®
Alon
Amit
,
518384649
®
Sofia
Sofia
Lambropoulou
,
537904839
®
Leo
Shatz
,
592958791
®
Gil
Kalai
,
601197211
®
Jordan
Watts
,
602566006
®
Lucy
Liuxuan
Zhang
,
629236983
®
Yizhar
Karshon
,
630958375
®
Adam
Sikora
,
645071421
®
Karene
Chu
,
660568189
®
Nathan
Dunfield
,
681989249
®
Stella
Huerfano
,
760185496
®
Louis
Leung
,
806692228
®
Naomi
Saporta
,
811931121
®
Sergey
Arkhipov
,
900670622
®
Yevgeny
Liokumovich
,
1025700849
®
Daniel
Silver
,
1039601228
®
Raz
Kupferman
,
1052340413
®
Jim
Stasheff
,
1105992189
®
Hernando
Burgos
Soto
,
1113731655
®
Mikhail
Mazin
,
1139655038
®
Zsuzsanna
Dancso
,
1179589180
®
Nurit
Karshon
,
1199886686
®
Peter
Shalen
,
1220318157
®
Stavros
Garoufalidis
,
1309203465
®
Wieslawa
Niziol
,
1362217059
®
Stephen
French
Sawin
,
1379632937
®
Rafael
Katz
,
1407495660
®
Sam
Nelson
,
1466606922
®
Vivi
Einy
,
1606473860
®
Ali
Mousavidehshikh
,
1643850019
®
Lisha
Li
,
1690551845
®
Ella
Ginat
,
1785307254
®
Rachel
Hallote
,
100000021472557
®
Joanna
Kania
-
Bartoszynska
,
100000149095020
®
Songhao
Li
,
100000255887445
®
Tal
Shachar
,
100000344024829
®
,
100000406918516
®
Geula
Tziona
Pancirer
Gross
,
100000811697957
®
,
100000832506430
®
Greg
Kuperberg
,
100001018863186
®
Assaf
Bar
-
Natan
,
100001802477092
®
Scott
Carter
,
100001988742213
®
Lara
Poe
,
100002176912292
®
Yael
Karshon
,
100004760231426
®
Tamar
Ziegler
<
Extracting
Connections
mrtProgressBar
@
i$2200
,
groupsCompLen$2200
D
Connections
number
:
118
Extracting
user
pictures
:
mrtProgressBar
@
i$4211
,
47
D
Photo
'
s
number
:
47
Creating
GraphPlot
Creating
PDF
PDF
Created
!
4




Untitled-1