yichao firstname, zeaster nickname, zhang lastname

blogsync FAQ

 



blogsync FAQ


from http://code.google.com/p/blogsync-java/wiki/BlogsyncFAQ

what is blogsync?


it is used to import wordpress posts into blogger.

how to use it?



  • set jdk bin path in run.bat/run.sh

  • execute run.bat/run.sh


what is new in blogsync 0.3?


The comments can be imported from wordpress rss xml file to blogger site now. However it can not preserve the published time of the wordpress comments. so the published time of your imported comments is just the time when you import.

what is new in blogsync 0.2?


add feature to import posts from exported wordpress rss xml file to blogger site.

which jdk version do I need to run blogsync?


You should use jdk1.5 or later.

how to add jdk bin path in path environment?



  • windows

    1. says your java.exe is in directory c:\jdk1.5.0\bin

    2. set the following line in run.bat

    3.     set path=c:jdk1.5.0bin;%path%



  • Mac or unix

    1. says your java is in directory /path/to/your/java

    2. set the following line in run.sh

    3.     export PATH=/path/to/your/java:$PATH




how do I know which version of jdk I am using?


open a terminal, type "java -version". you should get something like this:
java version "1.5.0_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
Java HotSpot(TM) Client VM (build 1.5.0_12-b04, mixed mode)

how to run run.bat/run.sh in command line?



  • windows

  • open a command window, type:
        cd e:pathtoyourrun.bat
    run
    .bat


  • Mac or unix

  • open a terminal, type:
        cd /path/to/your/run.sh
    sh run
    .sh



when run run.sh, it is opened by my editor, what should I do?


please run run.sh in command line.

after clicking on run.bat/run.sh, there was nothing happend, what should I do?


run run.bat/run.sh in command line so that find what's going wrong in the terminal?

It prompts "java: command not found", what's going wrong?


java is not in your path, please add jdk bin path in your path environment.

why do I get Exception in thread "main" java.lang.NoClassDefFoundError: org/easter/blogsync/BlogSync?


if you are on Mac or unix, please make sure you have read permission on blogsync/build/blogsync.jar file if not, open a terminal and type:
chmod 744 /path/to/your/blogsync/build/blogsync.jar

why do I get Failed to create input stream: Server returned HTTP response code: 403 for URL: http://mydomain.com/wordpress/xmlrpc.php?



  • if you installed a plugin called Enforce www. Preference, it would affect the path to your xmlrpc.php file, so deactivated it first.

  • if you enabled mod_security on apache, it would block access to xmlrpc.php, so add this to your .htaccess file:

  •     <Files xmlrpc.php>
    SecFilterInheritance Off
    </Files>


python script to email me the dynamic ip from tp-link router

At home, my boxes are connected to internet by Beijing ADSL.
when connected, Beijing ADSL gives me a dynamic ip and it changes about every 24 hours.
Before I get the dynamic ip by a service provided by oray.net.
However recently the service is broken.
So I have to write a python script to check the dynamic ip from my tp-link router every 3 minutes and if it changed, emails the new dynamic ip to my gmail.

I also write a bash script to run the above python script at boot on my gentoo linux.

The python script:


#!/usr/bin/python

import urllib
import urllib2
import libgmail
import cookielib
import sys
import re
import base64
import socket
import time
from urlparse import urlparse

nowip=''
logfile=open('/var/log/ipsender.log','w')

def log(s):
now=time.strftime('%Y-%m-%d %X')
logfile.write('%s %sn'%(now,s))
logfile.flush()

def gmailsender(to_addr,subject,msg):
username='xxx@gmail.com'
password='xxx'
ga=libgmail.GmailAccount(username,password)
ga.login()
gmsg=libgmail.GmailComposedMessage(to_addr,subject,msg)
ga.sendMessage(gmsg)

def check():
global nowip
timeout=10
socket.setdefaulttimeout(timeout)
username = 'admin'
password = 'xxx'
try:
theurl='http://192.168.1.1/userRpm/StatusRpm.htm'
req = urllib2.Request(theurl)
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
handle = urllib2.urlopen(req)
str=handle.read()
ss='var wanPara = new Array'
start=str.index(ss)+ss.__len__()
end=str.index(';',start)
s2=str[start:end]
log(s2)
t=eval(s2)
log(t[2])
handle.close()
if nowip!=t[2]:
nowip=t[2]
gmailsender('mygmail@gmail.com','ddnsip===%s'%nowip,s2)
log('send %s successfully.'%nowip)
else:
log('ddnsip remains %s.'%nowip)
except:
log('Unexpected error:', sys.exc_info()[0])

def main():
while True:
check()
time.sleep(3*60)

main()

The bash script put in /etc/init.d/:

#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
start() {
ebegin "Starting ipsender"
nohup python /home/zeaster/amp/ipsender.py >> /var/log/ipsender-nohup.log&
eend $?
}
stop() {
ebegin "Stopping ipsender unsuccessfully"
eend $?
}

wake-on-lan by python script

How to wake up your computer on the LAN?
the answer is just to send a Magic Packet to your computer on port 7 or 9.
However when your computer is down, it has no ip, so send it to the broadcast ip
the following python script implements the above idea.


import struct, socket

def wake_on_lan(ether_addr, inet_addr):
addr_byte=ether_addr.split(':')
hw_addr=struct.pack('BBBBBB',
int(addr_byte[0],16),
int(addr_byte[1],16),
int(addr_byte[2],16),
int(addr_byte[3],16),
int(addr_byte[4],16),
int(addr_byte[5],16))
msg='\xff'*6+hw_addr*16

s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, (inet_addr,7))
s.close()

wake_on_lan('00:E0:4C:E1:D9:CC', '192.168.1.255')


The code above is based on socket.SOCK_DGRAM to send UDP packet.
How to create a UDP packet based on raw socket in python?
the project dpkt does an excellent job.
the following example shows that:

import socket
from dpkt import ethernet,udp,ip
import dpkt
import struct
import string

iface = "eth1"
mac = "00:0E:35:AB:9B:40"
inet = "192.168.1.6"
debug = 0

def eth_aton(buffer):
addr =''
temp = string.split(buffer,':')
buffer = string.join(temp,'')
for i in range(0, len(buffer), 2):
addr = ''.join([addr,struct.pack('B', int(buffer[i: i + 2], 16))],)
return addr

def buildUdp():
ether_addr='00:E0:4C:E1:D9:CD'
addr_byte=ether_addr.split(':')
hw_addr=struct.pack('BBBBBB',
int(addr_byte[0],16),
int(addr_byte[1],16),
int(addr_byte[2],16),
int(addr_byte[3],16),
int(addr_byte[4],16),
int(addr_byte[5],16))
msg='xff'*6+hw_addr*16

udp_p = udp.UDP()
udp_p.sport = 0x8130
udp_p.dport = 7
udp_p.data = msg
udp_p.ulen += len(udp_p.data)

ip_p = ip.IP()
ip_p.src = socket.inet_aton('192.168.1.6');
ip_p.dst = socket.inet_aton('192.168.1.255');
ip_p.off = 0x4000
ip_p.data = udp_p
ip_p.p = ip.IP_PROTO_UDP
ip_p.len += len(udp_p)

packet = ethernet.Ethernet()
packet.src = eth_aton(mac)
packet.dst = eth_aton('ff:ff:ff:ff:ff:ff')
packet.data = ip_p
packet.type = ethernet.ETH_TYPE_IP

if debug: print dpkt.hexdump(str(packet))
return packet

s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW)
s.bind((iface,ethernet.ETH_TYPE_IP))
packet = buildUdp()
s.send(str(packet))

blogsync 0.3 released, comments can be imported.

Firstly, the foregoing blogsync 2.0 should be blogsync 0.2. :-)
blogsync is a tool that import your wordpress to blogger from rss xml file or online

Now it's blogsync 0.3 release. and it can import comments from exported wordpress rss xml file to blogger site.
it can be downloaded from:
http://code.google.com/p/blogsync-java/downloads/list

however it can not preserve the published time of the original comments.
so the published time of your imported comment is just the time when you import.
more details can be found at
http://groups.google.com/group/bloggerDev/browse_thread/thread/15c9a45416305f99

blogsync 2.0 released, import your wordpress to blogger from rss xml file or online

It's open source now and comes with new feature.

1 project hosted:
at http://code.google.com/p/blogsync-java
blogsync 0.2 can be downloaded at
http://blogsync-java.googlecode.com/files/blogsync-0.2.zip

2 new feature:
In previous blogsync, it imports wordpress posts to blogger from your wordpress website online.
Now in blogsync 0.2, it can import wordpress posts to blogger from a rss xml file that exported by wordpress.

when blogsync 0.1, the common errors are such as:
a)[Fatal Error] :1444:21: Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse
servers response: Invalid byte 1 of 1-byte UTF-8 sequence.
b)Fatal Error] :1:1: Content is not allowed in prolog.

this is because
a) the server response is not in utf-8 encoding. or
b) the server response is not a valid xml.

when your posts are too big, for example, http://i978.iyublog.com, when export all of this blog's posts, the exported rss xml file is 2064KB.
so when transferring these data through http online, the above errors are easy to reproduce.

Few days ago, I tried to export all posts to a rss xml file, then imports these posts locally from the exported xml file, the above error is hard to reproduce again.
the worst case is that your export file is still invalid xml file or wrong encoding, however it's easy to find these errors and you can try to export it again or edit it manually until you get a valid utf-8 xml file. Now you can import these posts to blogger from the valid utf-8 rss xml file by blogsync 2.0.

ps:
how to export your wordpress posts to a rss xml file?
in wordpress admin page, go to "Manage" page -> "Export" page, there is a link to export all of your posts.

ps2:
within 24 hours, Google allows us to submit at most 50 posts by googe data api.
so after 50 posts, the tool can not import any. only to wait for another 24 hours.

统一Mac OS X,Windows XP/Vista以及linux的系统时间

Windows把BIOS时间作为系统时间,而Mac OS X把BIOS时间作为GMT+0时间,所以对于生活在GMT+8时区的中国用户来说,这两个系统共存时系统时间是不一致的。
即:如果windows时间为12:00,则到Mac OS X下就变成了20:00,在Mac OS X下改过来后,再回到windows下就又错了。

之前看过这篇blog,讲了通过修改windows注册表,使得windows也把bios时间作为GMT+0时间,这样就可以解决这个问题了,具体操作如下:
在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\中加一项DWORD,RealTimeIsUniversal,把值设为1即可。

这个办法是靠调整windows时间设置来解决问题的,但是当系统中有linux时,因为linux也是使用bios时间作为系统时间,所以这时linux系统的时间就又不一致了。
最好的办法就是调整Mac OS X的时间。于是想到了强大的Bash Shell,先写脚本1用来开机时自动把时间校对准,然后关机时再运行脚本2,把时间调整回去。
脚本1:
#!/bin/bash
d=$(date "+%d")
H=$(date "+%H")
M=$(date "+%M")
S=$(date "+%S")
let "H=$H-16"

z=0
if [ "$H" -lt "$z" ]
then
  let "H=$H+24"
  let "d=$d-1"
fi

z=10

if [ "$d" -lt "$z" ]
then
  d=0$d
fi

if [ "$H" -lt "$z" ]
then
  H=0$H
fi

sudo date -u $d$H$M.$S

脚本2
#!/bin/bash
ss=$(date "+%d%H%M.%S")
sudo date -u $ss

那么如何实现自动开机运行以及关机自动运行呢?
1 开机自动运行
写shell,然后在applescript中调用shell,再把applescript保存为app,添加到login items中
注:我的.sh文件和textmate做绑定了,这样直接添加.sh文件不会执行shell,而是被textmate打开

2 关机自动运行
使用launchbar的restart和shutdown applescript,因此只需在这两个script中添加调用shell的一句即可了。

bash shell修改系统时间需要root权限,那么如何在applescript中调用时输入root密码呢?
使用如下命令:
do shell script "sudo date -u 1200" password "mypwd" with administrator privileges

推荐一本书:中国自行车之旅

前面介绍了如何选购适合自己的自行车,以及一些基本修车技术,足以应付长途骑行的需要。
后面是全国各地的骑行路线介绍,很实用!

PS 1:
本来想引用豆瓣上关于这本书的链接,结果发现没有,仔细一查才发现原来:
在豆瓣上已无法添加《中国自行车之旅》一书,因为《中国自行车之旅》和《中国徒步之旅》这两本书的isdn号都是7561327234
  这两部书见:
  http://joyo.com/detail/product.asp?prodid=bkbk404144
  http://joyo.com/detail/product.asp?prodid=bkbk410714

PS 2:
看过之后,决定今年春季去一次十三陵水库,那位想一同去,可以留言。

性能准则之一:在遍历集合前一定要判断集合是否为空

例举2个例子:
1使用Iterator对象遍历集合时,此时遍历前检查集合大小可以缩短执行时间约为:64%

  public static void main(String[] args) {
    int N = 1000 * 100000;
    List<Integer> list = new ArrayList<Integer>();

    long start = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
      Iterator<Integer> iter = list.iterator();
      while (iter.hasNext()) {
        System.out.println(iter.next());
      }
    }

    System.out.println(System.currentTimeMillis() - start);                      //==================490
    start = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
      int j = list.size();
      if (j > 0) {
        Iterator<Integer> iter = list.iterator();
        while (iter.hasNext()) {
          System.out.println(iter.next());
        }
      }
    }
    System.out.println(System.currentTimeMillis() - start);                     //==================180          时间缩短了64%
  }


2 使用for循环遍历集合时,此时遍历前检查集合大小可以缩短执行时间约为:5%
  public static void main(String[] args) {
    int N = 1000 * 10000;
    List<Integer> list = new ArrayList<Integer>();

    long start = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
      int j = list.size();
      for (int t = 0; t < j; t++) {
        System.out.println(list.get(t));
      }
    }

    System.out.println(System.currentTimeMillis() - start);          //==================190
    start = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
      int j = list.size();
      if (j > 0) {
        for (int t = 0; t < j; t++) {
          System.out.println(list.get(t));
        }
      }
    }
    System.out.println(System.currentTimeMillis() - start);         //==================180     时间缩短了5%
  }

blogsync with gui coming, import your wordpress to blogger

blogsync with gui coming

and with some control function about which posts to import.

it can be downloaded from
http://yichao.zhang.googlepages.com/blogsync-with-gui.tar.gz

Readme.txt

0. What is it used for?
This is a simple tool to import all posts from wordpress to blogger/blogspot.

1. How to use it?
0) set java in your path.
for windows users, run run.bat
for unix/mac users, run run.sh
1) set up your wordpress and blogger account.
2) choose one import option from option panel.
3) read posts from wordpress.
4) check posts and remove any posts that you do not want to import by selecting and right-clicking.
5) import now by just clicking the import button.

2. what is my blogger blogid?
It's in your blogspot Dashboard url, for example: http://www2.blogger.com/posts.g?blogID=18083698
"18083698" is your blogid.

3. what may cause this error?
[Fatal Error] :1444:21: Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse
servers response: Invalid byte 1 of 1-byte UTF-8 sequence.

One of your posts may be an invalid xml.
please correct it and make sure its source code is valid xml, then import again.

4. any other questions?
Welcome to send your feedback to Yichao.Zhang & gmail.com
or leave me a comment on http://zeaster.blogspot.com