Social Graph API をPythonでやってみた

気になったのでやってみた。
自分のtwitterのページでFollowされているのを取得する。

まずはベースとなるURLが

http://socialgraph.apis.google.com/lookup

こちらは、
GoogleCodeに記載されている。
http://code.google.com/apis/socialgraph/

で引数を決める。
今回使用したのは、

・pretty(インデント・改行される。)
・callback(コールバック関数を指定)
・edo(FollowしているURLを表示させる)

In [1]: base_url = ‘http://socialgraph.apis.google.com/lookup?q=http://twitter.com/kishir&pretty=1&callback=foo&
edo=1’

In [2]: html = opener.open(base_url).read()

In [3]: print html
foo({
 ”canonical_mapping”: {
  ”http://twitter.com/kishir”: “http://twitter.com/kishir”
 },
 ”nodes”: {
  ”http://twitter.com/kishir”: {
   ”attributes”: {
    ”url”: “http://twitter.com/kishir”,
    ”profile”: “http://twitter.com/kishir”,
    ”rss”: “http://twitter.com/statuses/user_timeline/kishir.rss”,
    ”atom”: “http://twitter.com/statuses/user_timeline/kishir.atom”
   },
   ”nodes_referenced”: {
    ”https://kishi-r.com/”: {
     ”types”: [
      ”me”
     ]
   },
    ”http://twitter.com/kano_e”: {
     ”types”: [
      ”contact”
     ]
    },
    ”http://twitter.com/soundkitchen”: {
     ”types”: [
      ”contact”
     ]
    },
    ”http://twitter.com/tasukuchan”: {
     ”types”: [
      ”contact”
     ]
    },
    ”http://twitter.com/yoshuki”: {
     ”types”: [
      ”contact”
     ]
    }
   }
  }
 }
});

なんでだろう?
Followされているユーザーが全て表示されない。
引数「q」に他のURLを加えると増えるのだが、
それも良くわからないなぁ~。

もうちょっと試してみるかな。

PythonでBeautiful Soupを試してみる。

PythonでHTMLの解析を行うのによさそうだったので、
試してみることにした。

まず必要なのが、

BeautifulSoup

まずインストール(ってかファイルをPythonが読める場所にBeautifulSoup.pyを置くだけ。)

ここからダウンロードする。
それを今回は「site-packages」の下に置いてみた。
清水川Webを参考にさせてもらったためです。

やってみます。

>>> import urllib2
>>> opener = urllib2.build_opener()
>>> html = opener.open(‘https://kishi-r.com/2008/02/ubuntu_1.html’).read()
>>> print html

HTML内の情報が表示されました。
ここでBeautifulSoupを使って「title」のみを解析してみます。

>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup(html)
>>> soup.find(‘title’,)
<title>kishi-r.com: Ubuntuをインストールしました。</title>

取れたっすね。

他にも「td」を検索してみる。

>>> soup.findAll(‘td’,)
[<td>
</td>, <td>
</td>, <td>
</td>, <td>
</td>, <td>
</td>, <td><span class=”today”>
<a href=”https://kishi-r.com/2008/02/01/”>1</a>
</span></td>, <td><span class=”calendar”>
2</span></td>, <td><span class=”calendar”>
3</span></td>, <td><span class=”calendar”>
4</span></td>, <td><span class=”calendar”>
5</span></td>, <td><span class=”calendar”>
6</span></td>, <td><span class=”calendar”>
7</span></td>, <td><span class=”calendar”>
8</span></td>, <td><span class=”calendar”>
9</span></td>, <td><span class=”calendar”>
10</span></td>, <td><span class=”calendar”>
11</span></td>, <td><span class=”calendar”>
12</span></td>, <td><span class=”calendar”>
13</span></td>, <td><span class=”calendar”>
14</span></td>, <td><span class=”calendar”>
15</span></td>, <td><span class=”calendar”>
16</span></td>, <td><span class=”calendar”>
17</span></td>, <td><span class=”calendar”>
18</span></td>, <td><span class=”calendar”>
19</span></td>, <td><span class=”calendar”>
20</span></td>, <td><span class=”calendar”>
21</span></td>, <td><span class=”calendar”>
22</span></td>, <td><span class=”calendar”>
23</span></td>, <td><span class=”calendar”>
24</span></td>, <td><span class=”calendar”>
25</span></td>, <td><span class=”calendar”>
26</span></td>, <td><span class=”calendar”>
27</span></td>, <td><span class=”calendar”>
28</span></td>, <td><span class=”calendar”>
29</span></td>, <td>
</td>]

で取れました。

このBeautifulSoupを使った記事でおもしろそうだったのが、
Googleニュースで指定した単語を検索して、ヒット数を返すサンプルなどがありました。
とりあえず試してみようっと。

Ubuntuをインストールしました。

以前購入したサーバにUbuntuをインストールしました。

バージョンは、

Ubuntu 7.10(コード名:Gusty Gibbon)

です。
CentOSの時とちょこちょこ違う箇所がありましたが、
そこらへんをWikiにメモしました。

あ、
Djangoが動くか試してないや。。。
とりあえずTracが動いてMySQlも動いて、
Subversionも動いてたしこれから色々と
やってみようっと。
とりあえず必要なものはほぼ入ったしね。

DJ Deckstream / Sweet 90’s Blues(2LP) を購入

やっと買えた。
これず~っと欲しかったレコードっす。

最後のCommonとか最高っすね。
それも2LPで2,100円って安いなぁ~。

A1, Nine / Make Or Take – Remix
A2, Bahamadia / 3Tha Hard Way
A3, INI feat, Pete Rock / Fakin Jax – Remix
B1, Das EFX / Real Hip Hop – Remix
B2, Kool G Rap / Fast Life – Remix
C1, Mobb Deep / Shooke Ones Part 2 – Remix
C2, Pitch Black / Show? Prove – Remix
C3, Nas / Life’s A Bitch – Remix
D,1 Camp Lo / Luchini aka This is it – Remix
D,2 Beat Nuts / Props Over Here – Remix
D,3 Common / I Used love H,E,R – Remix

ついでにDJ DeckstreamのMixCDも購入。

なかなか良かったが、
ちょっと前まで配布していた
DJ田松のGET FRESH!!!がやばすぎる。
最近それしか聴いてないって位聴き倒してる。

他にも

Aicube Music Present / Beautiful Field
もなかなか良かった。
ほぼインストだからかなり好み。

最近やっとCDを買うようになって、
結構増えてきた感があるなぁ~。
収集癖があるからちょっとうれしいw

PHPってそんなに・・・

最近PHPをディスるってのが、
はやっているみたいw

でもディスるってのも久々に聞いたから、
ウケるw

90年代のHIPHOPでは結構聞いたけどなぁ~。
ICE CUBEとCypress Hillとかがディスってるレコードも
持ってるし。

でも向こうでは本当に殺されるから怖い。
2PacとかNotorious BIGとかもそうだもんなぁ~。
好きだったのに・・・。

まぁ~ネタだから、
そんなことが起きないように願ってます。

自分自身PHPからプログラムを始めたんですが、
PHPには感謝してます。
だってそれがきっかけだから。
一番大事ですよね。