NE(ねとわーくえんぎにあ)日記 このページをアンテナに追加 RSSフィード


日々の記録はこちら / twitter

2010-11-20 Pythonでtwitterのタイムライン取得 このエントリーを含むブックマーク このエントリーのブックマークコメント

Twitterのタイムラインは最新200件しか取得できず、未読を追いきれません。

良いもの。悪いもの。: コマンドラインで動作するOAuth対応TwitterクライアントをPythonで作ってみたを参考に、タイムライン取得スクリプトを作成してcronで回そうと思います。

環境はUbuntu8.04ですが、インストールoauth-python-twitterだけで大丈夫です。

python-twitteroauthは自動的にダウンロードインストールされます


oauth-python-twitterダウンロード

$ svn export http://oauth-python-twitter.googlecode.com/svn/trunk/ oauth-python-twitter
A    oauth-python-twitter
A    oauth-python-twitter/.hgignore
A    oauth-python-twitter/oauthtwitter
A    oauth-python-twitter/oauthtwitter/__init__.py
A    oauth-python-twitter/setup.py
A    oauth-python-twitter/README
リビジョン 19 をエクスポートしました。

oauth-python-twitter/oauthtwitter/__init__.pyを書き換え。

$ diff -dru oauth-python-twitter/oauthtwitter/__init__.py.org oauth-python-twitter/oauthtwitter/__init__.py
--- oauth-python-twitter/oauthtwitter/__init__.py.org   2010-07-29 18:22:31.000000000 +0900
+++ oauth-python-twitter/oauthtwitter/__init__.py       2010-11-20 19:07:28.000000000 +0900
@@ -192,6 +192,10 @@
         token = self._FetchUrl(url, no_cache=True)
         return oauth.OAuthToken.from_string(token)

+    def getAccessTokenWithPin(self, pin, url=ACCESS_TOKEN_URL):
+        token = self._FetchUrl(url, parameters={"oauth_verifier": pin}, no_cache=True)
+        return oauth.OAuthToken.from_string(token)
+
     def getRequestToken(self, url=REQUEST_TOKEN_URL):
         '''Get a Request Token from Twitter

oauth-python-twitterのbuildとインストール。(simplejson)

$ cd oauth-python-twitter/

$ python setup.py build
running build
running build_py
creating build
creating build/lib
creating build/lib/oauthtwitter
copying oauthtwitter/__init__.py -> build/lib/oauthtwitter

$ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating oauth_python_twitter.egg-info
writing requirements to oauth_python_twitter.egg-info/requires.txt
writing oauth_python_twitter.egg-info/PKG-INFO
writing top-level names to oauth_python_twitter.egg-info/top_level.txt
writing dependency_links to oauth_python_twitter.egg-info/dependency_links.txt
writing manifest file 'oauth_python_twitter.egg-info/SOURCES.txt'
reading manifest file 'oauth_python_twitter.egg-info/SOURCES.txt'
writing manifest file 'oauth_python_twitter.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/oauthtwitter
copying build/lib/oauthtwitter/__init__.py -> build/bdist.linux-x86_64/egg/oauthtwitter
byte-compiling build/bdist.linux-x86_64/egg/oauthtwitter/__init__.py to __init__.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying oauth_python_twitter.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/oauth_python_twitter-1.1-py2.5.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing oauth_python_twitter-1.1-py2.5.egg
Copying oauth_python_twitter-1.1-py2.5.egg to /usr/lib/python2.5/site-packages
Adding oauth-python-twitter 1.1 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/oauth_python_twitter-1.1-py2.5.egg
Processing dependencies for oauth-python-twitter==1.1
Searching for python-twitter>=0.6
Reading http://pypi.python.org/simple/python-twitter/
Reading http://code.google.com/p/python-twitter/
Best match: python-twitter 0.6
Downloading http://python-twitter.googlecode.com/files/python-twitter-0.6.tar.gz
Processing python-twitter-0.6.tar.gz
Running python-twitter-0.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l_o36F/python-twitter-0.6/egg-dist-tmp-evic1K
zip_safe flag not set; analyzing archive contents...
Adding python-twitter 0.6 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/python_twitter-0.6-py2.5.egg
Searching for simplejson>=2.0.9
Reading http://pypi.python.org/simple/simplejson/
Reading http://undefined.org/python/#simplejson
Best match: simplejson 2.1.2
Downloading http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.2.tar.gz#md5=a856f9ae9ab3749991a93ddeafadc554
Processing simplejson-2.1.2.tar.gz
Running simplejson-2.1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Ho4rp8/simplejson-2.1.2/egg-dist-tmp-ODEVt1
Adding simplejson 2.1.2 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/simplejson-2.1.2-py2.5-linux-x86_64.egg
Searching for oauth>=1.0a
Reading http://pypi.python.org/simple/oauth/
Reading http://code.google.com/p/oauth
Best match: oauth 1.0.1
Downloading http://pypi.python.org/packages/source/o/oauth/oauth-1.0.1.tar.gz#md5=30ed3cc8c11d7841a89feab437aabf81
Processing oauth-1.0.1.tar.gz
Running oauth-1.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-PSEgpD/oauth-1.0.1/egg-dist-tmp-HftgGl
Adding oauth 1.0.1 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/oauth-1.0.1-py2.5.egg
Searching for setuptools==0.6c8
Best match: setuptools 0.6c8
setuptools 0.6c8 is already the active version in easy-install.pth
Installing easy_install script to /usr/bin
Installing easy_install-2.5 script to /usr/bin
Installing easy_install-2.4 script to /usr/bin

Using /usr/lib/python2.5/site-packages
Finished processing dependencies for oauth-python-twitter==1.1

注意:

  • hardy-backportsにpython-oauthパッケージがありますが、古いので使わないほうがいいでしょう。

  • tw.pyを起動すると"urllib2.HTTPError: HTTP Error 401: Unauthorized"がエラーが出る場合。

OAuthクライアントの登録をして、tw.pyの以下を書き換えましょう

CONSUMER_KEY    = "CONSUMER_KEY"
CONSUMER_SECRET = "CONSUMER_SECRET"

  • PINを入れると、"AttributeError: 'OAuthApi' object has no attribute 'getAccessTokenWithPin'"エラーが出る場合。

→getAccessTokenWithPinの追加忘れです。


  • buildのエラー
$ python setup.py build
Traceback (most recent call last):
  File "setup.py", line 1, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

と言われたら、

$ sudo aptitude install python-setuptools

しましょう。


  • simplejsonのbuildでWARNING
***************************************************************************
WARNING: The C extension could not be compiled, speedups are not enabled.
Failure information, if any, is above.
I'm retrying the build without the C extension now.
***************************************************************************
***************************************************************************
WARNING: The C extension could not be compiled, speedups are not enabled.
Plain-Python installation succeeded.
***************************************************************************

このようなWARNINGが表示された場合は、

$ sudo aptitude install python-dev

しましょう。

2010-11-13 mobircのsendボタン このエントリーを含むブックマーク このエントリーのブックマークコメント

mobircajax UIにあるsendボタンが、Chrome devでもIE6でも動かなかったので、手を入れてみました。

$ diff -dru assets/tmpl/ajax/base.mt.org assets/tmpl/ajax/base.mt
--- assets/tmpl/ajax/base.mt.org        2010-11-13 12:43:27.000000000 +0900
+++ assets/tmpl/ajax/base.mt    2010-11-13 16:04:45.000000000 +0900
@@ -54,7 +54,7 @@
                         <div id="ChannelLog">log pain</div>
                         <form onsubmit=" return false;" id="CommandForm">
                             <input type="text" id="msg" name="msg" size="30" autocomplete="off" />
-                            <input type="button" value="send" id="SendButton" />
+                            <input type="submit" value="send" id="SendButton" />
                         </form>
                     </div>
                     <div id="CombinedLog" class="ui-layout-south">combined log pain</div>

assets/tmpl/i_phone/base.mtinput type="button"ですが、こちらはちゃんと動いています。

2009-06-20 Ubuntu 9.04気になるWARNING

[]RAID5拡張メモ RAID5拡張メモを含むブックマーク RAID5拡張メモのブックマークコメント

Ubuntu9.10で1TB*3のRAID5を1TB*4のRAID5に拡張

$ sudo fdisk /dev/sdd
デバイスは正常な DOS 領域テーブルも、Sun, SGI や OSF ディスクラベルも
含んでいません
Building a new DOS disklabel with disk identifier 0xb43cc2c8.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


このディスクのシリンダ数は 121601 に設定されています。
間違いではないのですが、1024 を超えているため、以下の場合
に問題を生じうる事を確認しましょう:
1) ブート時に実行するソフトウェア (例. バージョンが古い LILO)
2) 別の OS のブートやパーティション作成ソフト
   (例. DOS FDISK, OS/2 FDISK)
警告: 領域テーブル 4 の不正なフラグ 0x0000 は w(書き込み)によって
正常になります

コマンド (m でヘルプ): n
コマンドアクション
   e   拡張
   p   基本領域 (1-4)
p
領域番号 (1-4): 1
最初 シリンダ (1-121601, 初期値 1):
初期値 1 を使います
Last シリンダ, +シリンダ数 or +size{K,M,G} (1-121601, 初期値 121601):
初期値 121601 を使います

コマンド (m でヘルプ): w
領域テーブルは交換されました!

ioctl() を呼び出して領域テーブルを再読込みします。
ディスクを同期させます。

$ sudo mdadm /dev/md0 -a /dev/sdd1
mdadm: added /dev/sdd1


$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3](S) sdb1[1] sdc1[2] sda1[0]
      1953519872 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>

$ sudo mdadm --grow /dev/md0 --raid-devices=4
mdadm: Need to backup 384K of critical section..
mdadm: ... critical section passed.

<再構築中>
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3] sdb1[1] sdc1[2] sda1[0]
      1953519872 blocks super 0.91 level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
      [>....................]  reshape =  0.0% (174528/976759936) finish=1398.3min speed=11635K/sec

unused devices: <none>

$ sudo mdadm -D /dev/md0
/dev/md0:
        Version : 00.91
  Creation Time : Sun Mar  2 23:21:28 2008
     Raid Level : raid5
     Array Size : 1953519872 (1863.02 GiB 2000.40 GB)
  Used Dev Size : 976759936 (931.51 GiB 1000.20 GB)
   Raid Devices : 4
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jun  7 18:28:20 2009
          State : clean, recovering
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

 Reshape Status : 0% complete
  Delta Devices : 1, (3->4)

           UUID : 2ff3701f:d46c900e:e368bf24:bd0fce41
         Events : 0.653070

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
       2       8       33        2      active sync   /dev/sdc1
       3       8       49        3      active sync   /dev/sdd1

<再構築完了>
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3] sdb1[1] sdc1[2] sda1[0]
      2930279808 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>

$ sudo mdadm -D /dev/md0
/dev/md0:
        Version : 00.90
  Creation Time : Sun Mar  2 23:21:28 2008
     Raid Level : raid5
     Array Size : 2930279808 (2794.53 GiB 3000.61 GB)
  Used Dev Size : 976759936 (931.51 GiB 1000.20 GB)
   Raid Devices : 4
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Mon Jun  8 20:44:47 2009
          State : active
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : 2ff3701f:d46c900e:e368bf24:bd0fce41
         Events : 0.1302139

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
       2       8       33        2      active sync   /dev/sdc1
       3       8       49        3      active sync   /dev/sdd1

$ sudo xfs_growfs /dev/md0
meta-data=/dev/md0               isize=256    agcount=65, agsize=7630928 blks
         =                       sectsz=4096  attr=1
data     =                       bsize=4096   blocks=488379968, imaxpct=25
         =                       sunit=16     swidth=16 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=32768, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=0
realtime =none                   extsz=65536  blocks=0, rtextents=0
data blocks changed from 488379968 to 732569952

$ df -h
ファイルシステム            サイズ  使用  残り 使用% マウント位置
/dev/sde2             1.9G  1.4G  386M  79% /
tmpfs                 994M     0  994M   0% /lib/init/rw
varrun                994M  1.4M  993M   1% /var/run
varlock               994M     0  994M   0% /var/lock
udev                  994M  180K  994M   1% /dev
tmpfs                 994M     0  994M   0% /dev/shm
lrm                   994M  2.7M  991M   1% /lib/modules/2.6.28-11-server/volatile
/dev/md0              2.8T  1.9T  935G  67% /home/share
/dev/shm              994M  653M  342M  66% /tmp

2009-06-07 Ubuntu 9.04のML115へのインストール

Ubuntu 9.04のML115へのインストール Ubuntu 9.04のML115へのインストールを含むブックマーク Ubuntu 9.04のML115へのインストールのブックマークコメント

BE-2300に換装して0.8Vの800MHzにダウンクロックしているのですが、この状態だとインストーラ言語選択の後kernel panicでフリーズします。電圧とクロックをAutoに戻したところ問題なく進みました。

7.10だと問題なかったんですけど、下げすぎですかね。

Ubuntu 9.04にVMwareServer1.0.9 Ubuntu 9.04にVMwareServer1.0.9を含むブックマーク Ubuntu 9.04にVMwareServer1.0.9のブックマークコメント

モジュールコンパイルがそのままで通りません。

また、PAM周りが微妙で、インストールままだとコンソールにログインできません。

後でまとめます。

Ubuntu 9.04のOpenVPN Ubuntu 9.04のOpenVPNを含むブックマーク Ubuntu 9.04のOpenVPNのブックマークコメント

起動時にopenssl-blacklist絡み(というかPythonコードの書き方)でwarningが出ます。

https://bugs.launchpad.net/ubuntu/+source/openvpn/+bug/352170

無視すればいいのですが、こんな感じで書き直すとwarningは消えます。

(パッケージの修正待ったほうがいいと思いますが)

$ diff -dru /usr/sbin/openvpn-vulnkey.org /usr/sbin/openvpn-vulnkey
--- /usr/sbin/openvpn-vulnkey.org       2008-06-17 21:12:19.000000000 +0900
+++ /usr/sbin/openvpn-vulnkey   2009-06-08 00:13:23.534823891 +0900
@@ -19,7 +19,8 @@
 #

 from optparse import OptionParser
-import md5
+import hashlib
 import re
 import sys

@@ -65,7 +66,8 @@
             keyfile += line
     fh.close()

-    key = md5.new(keyfile).hexdigest()
+    key = hashlib.md5(keyfile).hexdigest()
     if key[12:] in db_lines:
         if not options.quiet:
             print "COMPROMISED: %s %s" % (key, f)

6/13追記

パッケージ修正されました。

2009-03-27 Gigabyte M528にUbuntu

Gigabyte M528Ubuntu Gigabyte M528にUbuntuを含むブックマーク Gigabyte M528にUbuntuのブックマークコメント

M528ですが、xpでまともに使えないので放置してます。

https://lists.ubuntu.com/archives/ubuntu-mobile/2009-March/002371.html

> Specifically, whether touchscreen, wifi and video acceleration is working

Under jaunty, no, no, and no: touchscreen is closed and binaries only

available for older Xorg versions, wifi requires a proprietary module,

and video acceleration requires newer Poulsbo drivers.

・・・。


touchscreenのUbuntuドライバはあるのですが、8.04決め打ちのバイナリしかありません。

"video acceleration requires newer Poulsbo drivers"っていうのはこれですね。

Ubuntu Weekly Recipe:第57回 VAIO Type Pを使う(2):各種ドライバの設定|gihyo.jp … 技術評論社

Poulsboチップセット内蔵のGMA500は,xserver-xorg-video-psbというドライバで動作します。しかしこのドライバはまだ8.10や9.04で利用されるXServer用の移植が完了しておらず,さらに旧来のDRMを経由して利用しなければいけません。8.10以降での利用が微妙な状態なのもこれが理由です(LP#269611)。

この問題はUbuntu MobileのPPA対応モジュールが用意されているのですが,諸般の事情によりアップデートカーネルに追いついておらず(2.6.24-16までしかモジュールがありません),手元でビルドを行う必要があります。


xpドライバも雲行き怪しいですし、mbookかドコモデータ定額+VAIO Pに逃げたいですね。

RHEL4でqlogicがfabric rediscovery対応したのは、U3から RHEL4でqlogicがfabric rediscovery対応したのは、U3からを含むブックマーク RHEL4でqlogicがfabric rediscovery対応したのは、U3からのブックマークコメント

Red Hat Enterprise Linux 4 Update 3 リリースノート

sysfsを通したファブリック再発見(fabric rediscovery)用のサポートが今回、 Red Hat Enterprise Linux 4 Update 3で利用できます。Qlogic(qla2xxx)とEmulex (lpfc)ファイバーチャンネル HBA ドライバ用には、以下のコマンドを実行して、新規の格納の為に再発見と再スキャンを実行します :


echo "1" > /sys/class/fc_host/hostXYZ/issue_lip

echo "- - -" > /sys/class/scsi_host/hostXYZ/scan

ここで、XYZは、ご使用のHBAのscsiホスト番号です。