接上一个主题,说说还原shortener url之后的url。现在有很多shortener url的网站,比如goo.gl, bit.ly等等,如果只是想知道原始的url,则这个网站不错http://untr.im,这里还有一个小脚本:
#!/bin/bash
#filename: getfullurl.sh
URL=$1
if test "x$URL" == ""; then
exit
fi
curl -q -d "url=$URL" http://untr.im/api/ajax/api | awk -F 'href="' '{print $3}' | awk -F '" rel="' '{print $1}'
运行:
sh getfullurl.sh http://goo.gl/rz2O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
192 170 170 170 0 22 56 7 0:00:03 0:00:03 --:--:-- 81
http://wiki.thc.org/gsm
最好得到 http://wiki.thc.org/gsm
1/08/2010
Use the Google URL Shortener API with Python
原文:http://d.hatena.ne.jp/LaclefYoshi/20091216/1260891200
http://goo.gl 是 Google的URL Shortener 服务,类似的有很多,比如 http://tinyurl.com,不过Google URL Shortener没有对外开放,目前只能通过 Google toolbar 和chromium的扩展程序(goo.gl url shortener)才能使用,但是这位日本的朋友通过分析Google toolbar的xpi中js代码,写出了这段python代码,比较佩服他啊,下面贴出他的代码,其中做了一个小小的改动,使得程序可以接收参数。
#!/usr/bin/python
""" Google URL Shortener
Usage: python goo.gl URL"""
# import struct
import urllib
import simplejson
def usage():
print __doc__
def _c(vals):
l = 0
for val in vals:
l += val & 4294967295
return l
def _d(l):
if l <= 0:
l += 4294967296
m = str(l)
o = 0
n = False
for char in m[::-1]:
q = int(char)
if n:
q *= 2
o += q / 10 + q % 10 # Math.floor(q / 10) + q % 10
else:
o += q
n = not(n)
m = o % 10
o = 0
if m != 0:
o = 10 - m
if len(str(l)) % 2 == 1:
if o % 2 == 1:
o += 9
o /= 2
return str(o) + str(l)
def _e(uri):
m = 5381
for char in uri:
# m = _c([m << 5, m, struct.unpack("B", char)[0]])
m = _c([m << 5, m, ord(char)])
return m
def _f(uri):
m = 0
for char in uri:
# m = _c([struct.unpack("B", char)[0], m << 6, m << 16, -1 * m])
m = _c([ord(char), m << 6, m << 16, -1 * m])
return m
def _make_auth_token(uri):
i = _e(uri)
i = i >> 2 & 1073741823
i = i >> 4 & 67108800 | i & 63
i = i >> 4 & 4193280 | i & 1023
i = i >> 4 & 245760 | i & 16383
h = _f(uri)
k = (i >> 2 & 15) << 4 | h & 15
k |= (i >> 6 & 15) << 12 | (h >> 8 & 15) << 8
k |= (i >> 10 & 15) << 20 | (h >> 16 & 15) << 16
k |= (i >> 14 & 15) << 28 | (h >> 24 & 15) << 24
j = "7" + _d(k)
return j
def get_short_url(uri, user):
if user is None:
user = 'toolbar@google.com'
token = _make_auth_token(uri)
opt = 'user='+user+'&'+urllib.urlencode({'url':uri})+'&auth_token='+token
# print opt
ggl_url = 'http://goo.gl/api/url'
res = urllib.urlopen(ggl_url, opt)
# print res.read()
short_url = simplejson.loads(res.read())['short_url']
return short_url
import sys, os
if __name__ == "__main__":
#print get_short_url("http://www.aida.t.u-tokyo.ac.jp/", None)
if len(sys.argv) == 2:
print get_short_url(sys.argv[1], None)
else:
usage()
http://goo.gl 是 Google的URL Shortener 服务,类似的有很多,比如 http://tinyurl.com,不过Google URL Shortener没有对外开放,目前只能通过 Google toolbar 和chromium的扩展程序(goo.gl url shortener)才能使用,但是这位日本的朋友通过分析Google toolbar的xpi中js代码,写出了这段python代码,比较佩服他啊,下面贴出他的代码,其中做了一个小小的改动,使得程序可以接收参数。
#!/usr/bin/python
""" Google URL Shortener
Usage: python goo.gl URL"""
# import struct
import urllib
import simplejson
def usage():
print __doc__
def _c(vals):
l = 0
for val in vals:
l += val & 4294967295
return l
def _d(l):
if l <= 0:
l += 4294967296
m = str(l)
o = 0
n = False
for char in m[::-1]:
q = int(char)
if n:
q *= 2
o += q / 10 + q % 10 # Math.floor(q / 10) + q % 10
else:
o += q
n = not(n)
m = o % 10
o = 0
if m != 0:
o = 10 - m
if len(str(l)) % 2 == 1:
if o % 2 == 1:
o += 9
o /= 2
return str(o) + str(l)
def _e(uri):
m = 5381
for char in uri:
# m = _c([m << 5, m, struct.unpack("B", char)[0]])
m = _c([m << 5, m, ord(char)])
return m
def _f(uri):
m = 0
for char in uri:
# m = _c([struct.unpack("B", char)[0], m << 6, m << 16, -1 * m])
m = _c([ord(char), m << 6, m << 16, -1 * m])
return m
def _make_auth_token(uri):
i = _e(uri)
i = i >> 2 & 1073741823
i = i >> 4 & 67108800 | i & 63
i = i >> 4 & 4193280 | i & 1023
i = i >> 4 & 245760 | i & 16383
h = _f(uri)
k = (i >> 2 & 15) << 4 | h & 15
k |= (i >> 6 & 15) << 12 | (h >> 8 & 15) << 8
k |= (i >> 10 & 15) << 20 | (h >> 16 & 15) << 16
k |= (i >> 14 & 15) << 28 | (h >> 24 & 15) << 24
j = "7" + _d(k)
return j
def get_short_url(uri, user):
if user is None:
user = 'toolbar@google.com'
token = _make_auth_token(uri)
opt = 'user='+user+'&'+urllib.urlencode({'url':uri})+'&auth_token='+token
# print opt
ggl_url = 'http://goo.gl/api/url'
res = urllib.urlopen(ggl_url, opt)
# print res.read()
short_url = simplejson.loads(res.read())['short_url']
return short_url
import sys, os
if __name__ == "__main__":
#print get_short_url("http://www.aida.t.u-tokyo.ac.jp/", None)
if len(sys.argv) == 2:
print get_short_url(sys.argv[1], None)
else:
usage()
11/18/2009
7/23/2009
xfce desktop 起不来
最近升级系统之后桌面没了,发现 xfdesktop 没有起来,于是手动运行,但报以下错误:
xfdesktop[5225]: starting up
process 5225: arguments to dbus_connection_send_with_reply_and_block() were incorrect, assertion "(error) == NULL || !dbus_error_is_set ((error))" failed in file dbus-connection.c line 3301.
This is normally a bug in some application using the D-Bus library.
D-Bus not built with -rdynamic so unable to print a backtrace
在网上搜了一圈,发现需要添加 /etc/dbus-1/system.d/nasz-user.conf:
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="dev">
<allow send_destination="org.freedesktop.Hal"
send_interface="org.freedesktop.Hal.Device"/>
<allow send_destination="org.freedesktop.Hal"
send_interface="org.freedesktop.Hal.Manager"/>
</policy>
</busconfig>
其中 dev 改为实际用户名,然后重启 dbus
/etc/init.d/dbus restart
再运行 xfdesktop & 即可。
xfdesktop[5225]: starting up
process 5225: arguments to dbus_connection_send_with_reply_and_block() were incorrect, assertion "(error) == NULL || !dbus_error_is_set ((error))" failed in file dbus-connection.c line 3301.
This is normally a bug in some application using the D-Bus library.
D-Bus not built with -rdynamic so unable to print a backtrace
在网上搜了一圈,发现需要添加 /etc/dbus-1/system.d/nasz-user.conf:
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="dev">
<allow send_destination="org.freedesktop.Hal"
send_interface="org.freedesktop.Hal.Device"/>
<allow send_destination="org.freedesktop.Hal"
send_interface="org.freedesktop.Hal.Manager"/>
</policy>
</busconfig>
其中 dev 改为实际用户名,然后重启 dbus
/etc/init.d/dbus restart
再运行 xfdesktop & 即可。
7/22/2009
7/13/2009
在 Gmail 中添加 Twitter Gadget
Twitter 现在已经被封锁了,但如果之前在 Gmail 有 Twitter Gadget 好像可以继续使用哦 :-),那么如果在 Gmail 中添加 Twitter Gadget呢?
1) 让 Gmail 支持 Gadget。进入Gmail Lab,找到 "Add any gadget by URL" 并将它 Enable;
2) 点击 Gmail 右上角的 "setting",选择 "Gadget";
3) 将 Twitter Gadget address: http://twittergadget.appspot.com/gadget-gmail.xml(SSL https://twittergadget.appspot.com/gadget-gmail.xml) 拷贝到地址栏中;
1) 让 Gmail 支持 Gadget。进入Gmail Lab,找到 "Add any gadget by URL" 并将它 Enable;
2) 点击 Gmail 右上角的 "setting",选择 "Gadget";
3) 将 Twitter Gadget address: http://twittergadget.appspot.com/gadget-gmail.xml(SSL https://twittergadget.appspot.com/gadget-gmail.xml) 拷贝到地址栏中;
订阅:
博文 (Atom)

