• Stars
    star
    186
  • Rank 200,791 (Top 5 %)
  • Language
    Python
  • Created about 11 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

人人好友关系

人人网好友关系图

恩,很大的题目,但做的很差。所以欢迎大家来fix

更新

2013-03-03

使用 graphviz 绘图, 但还保留了 networkx,使用它来删除节点和计算degree

现在运行 python local_graph.py 就会生成一张漂亮的关系图(现在还没有在图上标记用户名) 所以请确保计算机一正确安装 graphviz

debian系用户只要简单的运行下面的命令即可

sudo apt-get install graphviz

如何运行

  1. git clone 代码
  2. 安装 requirements.txt中的依赖,建议virtualenv
  3. cp account.example account 然后按照其中格式填写人人网帐号
  4. python local_graph.py

运行程序,一段时间后(不同的网络环境会导致抓取时间差异很大,在我这里一共用了40分钟) 程序正常退出。就会在目录中生成一张 result.png 图片。

renren_graphviz

下面是用 networkx 和 matplotlib生成的图片,新代码默认不再使用

renren

这是我校内好友的情况,可以看到这些好友明显是三个圈子:

  • 高中同学圈子
  • 大学同学圈子
  • 码农圈子

还有一些孤立(不属于这三个大圈子的同学)的好友,没有显示。

初衷

初衷总是美好的,当我随便试了几个陌生人后,发现一样可以查看他们的好友。于是我就想到了 两个玩法:

  1. 做一个网站,人们上来只要填写他的人人ID,就会动态的展现他的好友,好友之间的共同好友...
  2. 在一个网站上输入两个人人ID,然后找出这两个ID之间的好友链。

最有意思的是第二个,因为我相信像人人网这样的强关系网络,以及大量的用户,两个用户之间 肯定会有一条/多条好友链接。

端点 <-> A <-> B <-> C ...... X <-> Y <-> Z <-> 端点

当然这个也很难,没想到如何做,于是就做第一个想法。

美好的初衷是如何变成现在这个屌样的?

  1. 某晚,正在在爬好友测试的时候,发现总是爬不到一些人的好友。 然后才发现了一个悲剧的事实,(不过也是合理的):

    好友不是你想爬,想爬就能爬

    只有开放了对应权限的才能察看其好友。

    这下好了,上面的想法2彻底做不了了。想法1也退化成只能自娱自乐了。 也就是只能爬自己好友的好友了

  2. urllib2 怎么卡住呢?

    使用了gevent,我刚开始的模型是 对多个用户,以及同一个用户的好友, 都利用gevent的并发来爬, 测试了两次后, urllib2 无法 read, 到这里,一下卡住了。

    并发会卡住。顺序爬取很顺利,但太慢。 后来偶然发现,

    对同一个人不能并发的抓取, 但还可以对多个人并发

  3. 图太难看了

    本打算 angular.js + d3.js + gevent-socket.io 来动态的在web上绘图。 但心急,想看看能绘制出什么样的图,于是先用 networkx 和 matplotlib 来绘图

    然后才发现 绘制好友的共同好友 几乎不可能,点全部重叠在一起,看都没法看……

    然后又一次吊丝的退化到只显示自己的好友

    最后还花了几小时来调节 图像的显示 效果。。。

可能遇到的问题

怎么无法登录?

请确保你有一个 account 文件,里面第一行写用户名/email, 第二行写password

如果在确保 account 文件正确的情况下,程序还是无法登录,请用浏览器登录一次,再运行程序

显示一个 collect friends 后怎么就卡住呢?

其实不是卡住了,只是抓取好友比较慢,这时又没有输出,所以看着像卡住了,请耐心等待

最后的图太简单了吧,有什么意思吗?

我也不想这样啊,蛋疼,欢迎你来增强它的功能和效果

程序跑完后会报一个这样错误:

`Exception KeyError: KeyError(17784656,) in ignored...`

这个直接忽略掉,应该是某个库不是线程安全的。但这个对结果没有影响。

More Repositories

1

social-oauth

OAuth2 for Chinese social sites
Python
324
star
2

make-proxy

HTTP/HTTPS/Socks4/Socks5 proxy written in Erlang
Erlang
270
star
3

django-siteuser

Register, Login, OAuth2, Upload avatar...
Python
256
star
4

seven-cow

Yet another qiniu cloud storage Python SDK. More Pythonic, More simple to use
Python
132
star
5

django-social-login

[DISCARDED]A Django APP for Social accounts login via OAuth2 Service
Python
104
star
6

codebattle-ai

AI Example for Codebattle
Erlang
45
star
7

django-upload-avatar

A django app for upload avatars
Python
40
star
8

paper

Feel free about writing blog. This is a simple blog system, Just bloging, Implemented on bottle
Python
35
star
9

playground

Erlang
32
star
10

duckadmin

A Django reusable app for show and operate custom forms in admin.
Python
30
star
11

abchat

Abstract Simple Chat Server Based on Gevent
Python
24
star
12

timerush

Python Timer Framework
Python
21
star
13

djangowebsocket

Python
20
star
14

i3-dzen2-bridge

Bridged the i3status and dzen2 to make dzen2 display icons
Python
20
star
15

vim-linemovement

simplify the line movement in vim
Vim Script
20
star
16

unity3d-scripts

A Collections of useful Scripts/Examples for Unity3d
C#
18
star
17

codebattle-server

codebattle server
Erlang
17
star
18

daemonize

Python Daemonize
Python
15
star
19

redis-lua-scripts

Lua script using with Redis
Python
14
star
20

vim-alignment

Align What You Want!
Vim Script
13
star
21

eipp

A C++11 Header Only Library for using erlang ei library.
C++
13
star
22

python-gears

A BBS Based On Django.
JavaScript
11
star
23

myblogposts

Posts of my blog
10
star
24

learn-you-some-erlang-zh

learn you some erlang 的简体中文翻译
9
star
25

codebattle-client

unity3d client of codebattle
C#
7
star
26

TRsound

For prononnce words with a terminal translation
C
4
star
27

gstatus

display git log in browser
Python
3
star
28

codebattle-proto

proto files for codebattle
3
star
29

django-admin-lastlocation

Return the last location after editing some item
Python
3
star
30

dianjing

Python
2
star
31

myfirefox

firefox plugins
2
star
32

redis-benchmark

Erlang
2
star
33

notebook

Erlang
2
star
34

termgif

record your terminal to animated gif
C
2
star
35

arrow

Erlang Datetime Utils
Erlang
2
star
36

mytools

自己的一些脚本工具
Python
1
star
37

sudoku

sudoku solved in my own way
C++
1
star
38

aoi

C++
1
star
39

smoke

A set collections of WSGI Middleware
Python
1
star
40

sanguo-server

Python
1
star