虾米自动签到的python脚本

一个练手的小脚本,暂时只是实现了签到,还没有很完备的错误处理,而且在实现“全自动签到”上还没有想出什么合理的方案,先把代码贴上现丑了……

使用方法很简单

python xiami_auto_checkin.py email password

即把用户名(email)和密码作为参数传进去即可
如果你只是签固定的一个帐号,也可以直接将代码中的读参数改成赋值

这个代码只是最初的版本,你可以在这里看到最新的进展

#!/usr/bin/python
# encoding:utf-8

import re
import sys
import urllib
import urllib2
import cookielib

def check(response):
    """
    docstring for check
    """
    pattern = re.compile(r'<div class="idh">(已连续签到\d+天)</div>')
    result = pattern.search(response)
    if result: return result.group(1)
    return False
    pass

def main():
    """
    docstring for main
    """

    # Get email and password
    if len(sys.argv) != 3:
        print '[Error] Please input email & password as sys.argv!'
        return
    email = sys.argv[1]
    password = sys.argv[2]

    # Init
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
    urllib2.install_opener(opener)

    # Login
    login_url = 'http://www.xiami.com/web/login'
    login_data = urllib.urlencode({'email':email, 'password':password, 'LoginButton':'登陆',})
    login_headers = {'Referer':'http://www.xiami.com/web/login', 'User-Agent':'Opera/9.60',}
    login_request = urllib2.Request(login_url, login_data, login_headers)
    login_response = urllib2.urlopen(login_request).read()

    # Checkin
    checkin_pattern = re.compile(r'<a class="check_in" href="(.*?)">')
    checkin_result = checkin_pattern.search(login_response)
    if not checkin_result:
        # Checkin Already | Login Failed
        result = check(login_response)
        if result :
            print '[Succeed] Checkin Already!', email, result
        else:
            print '[Error] Login Failed!'
        return
    checkin_url = 'http://www.xiami.com' + checkin_result.group(1)
    checkin_headers = {'Referer':'http://www.xiami.com/web', 'User-Agent':'Opera/9.60',}
    checkin_request = urllib2.Request(checkin_url, None, checkin_headers)
    checkin_response = urllib2.urlopen(checkin_request).read()

    # Result
    result = check(checkin_response)
    if result:
        print '[Succeed] Checkin Succeed!', email, result
    else:
        print '[Error] Checkin Failed!'
    pass

if __name__=='__main__':
    main()

有任何问题,欢迎批评指正,更多更新信息,请参见这里

精简WordPress eXtended Rss (WXR) 文件格式

经过N次Import和数据库清空,终于将之前的WXR文件格式的完备集简化了。

简化原则是适应Sina2WordPress项目的需要,尽可能精简文件大小,删除了导入无效的(如博客标题、博客链接等)和从新浪博客中无法获取的(如评论者的链接和IP等)信息,还有item之前的的作者、分类和标签信息。作者在导入时可以指定的,反而加上会有可能的错误,分类和标签的信息用post中的分类和标签就可以自动统计了。没想明白为什么非要单独列出来,难道是为了空的分类和标签,那还要它干嘛?

一些必不可少的标签及错误总结:
1、wxr_version,缺少会提示“missing/invalid WXR version number”的错误
2、post_id,否则只会导入第一篇文章
3、status,否则都会显示成draft
4、post_type,否则无法导入
5、comment_approved,否则无法导入

P.S.post_id的问题纠结了好久,为什么官方不好好设计一下呢?至少觉得应该在Settings设定对应的选项的……

< ?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.1/"
>
<!--RSS版本号和名字空间的扩展,以上为固定内容-->

<channel>
	<wp:wxr_version>1.1</wp:wxr_version>
	<!--WXR格式版本号-->

	<item><!--页面或者日志内容,每个为一个item-->
		<title>Title test</title>
		<!--标题-->
		<content:encoded>< ![CDATA[Content_test]]></content:encoded>
		<!--这里是正文内容-->
		<wp:post_id>1</wp:post_id>
		<!--页面或日志的序号,两者使用同一序列-->
		<wp:post_date>2002-12-21 07:59:59</wp:post_date>
		<!--发表时间-->
		<wp:comment_status>open</wp:comment_status>
		<!--评论开启情况,open / closed-->
		<wp:status>publish</wp:status>
		<!--页面或日志状态,publish / draft / pending / private-->
		<wp:post_type>post</wp:post_type>
		<!--文章类型,post / page-->
		<wp:is_sticky>0</wp:is_sticky>
		<!--文章是否置顶,0 / 1-->

		<category domain="post_tag" nicename="tag_test">< ![CDATA[Tag Test]]></category>
		<category domain="category" nicename="category_test">< ![CDATA[Category Test]]></category>
		<!--
			日志或页面的标签和分类,可多个
			domain:标签对应post_tag,分类对应category
			nicename:对应标签或分类的URL友好名称
			<![CDATA[]]>:标签或分类的显示名称
		-->

		<wp:comment><!--评论,可多个-->
			<wp:comment_id>1</wp:comment_id>
			<!--自增序号,评论专用-->
			<wp:comment_author>< ![CDATA[anonymous]]></wp:comment_author>
			<!--评论者用户名-->
			<wp:comment_date>2012-12-21 07:59:59</wp:comment_date>
			<!--评论时间-->
			<wp:comment_content>< ![CDATA[Content of Comment]]></wp:comment_content>
			<!--评论内容-->
			<wp:comment_approved>1</wp:comment_approved>
			<!--评论是否被允许-->
			<wp:comment_parent>0</wp:comment_parent>
			<!--父评论,指定所回复的评论-->
		</wp:comment>
	</item>
</channel>
</rss>

WordPress eXtended Rss (WXR)文件格式解析

Sina2WordPress的第一步——解析WXR文件格式

WXR是Wordpress eXtended Rss的缩写,是WordPress针对博客信息特意设定的格式,它最大的优点是兼容性好,包含信息丰富

通过参照导出的文件,初步找到一个完备集(见下方代码),经测试在WP无任何内容情况下无信息缺漏错误现象

下方代码已经尽可能的注释了所有可能的标签和属性,并且由于一些标签和属性与Sina2WordPress关系不大,故未深究

< ?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.1/"
>
<!--RSS版本号和名字空间的扩展,以上为固定内容-->

<channel>
	<title>Blog Title</title>
	<!--博客的标题-->
	<link>http://blog.example.com</link>
	<!--博客的链接-->
	<description>Blog Description</description>
	<!--博客的说明/副标题-->
	<pubdate>Dec, 20 Jun 2012 23:59:59 +0000</pubdate>
	<!--WXR文件生成时间-->
	<language>en</language>
	<!--博客的语言,en / zh-cn-->
	<wp:wxr_version>1.1</wp:wxr_version>
	<!--WXR格式版本号-->
	<wp:base_site_url>http://example.com</wp:base_site_url>
	<!--网站根目录地址-->
	<wp:base_blog_url>http://blog.example.com</wp:base_blog_url>
	<!--博客根目录地址-->

	<wp:author><wp:author_id>1</wp:author_id><wp:author_login>admin_test</wp:author_login><wp:author_email>admin@example.org</wp:author_email><wp:author_display_name>< ![CDATA[AdMin test]]></wp:author_display_name><wp:author_first_name>< ![CDATA[AdMin]]></wp:author_first_name><wp:author_last_name>< ![CDATA[test]]></wp:author_last_name></wp:author>
	<!--
		作者列表,可多个
		wp:author_id:自增序号
		wp:author_login:用户名
		wp:author_email:邮箱
		wp:author_display_name:显示的作者名称
		wp:author_first_name、wp:author_last_name:如字面意,可为空,但需有<![CDATA[]]>
		P.S.< ![CDATA[**]]>可以理解成强制文本转换,保留文本中所有字符,以避免非法字符对XML文件的影响(后文不再赘述)
	-->

	<wp:category><wp:term_id>1</wp:term_id><wp:category_nicename>category_test</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name>< ![CDATA[分类测试]]></wp:cat_name></wp:category>
	<!--
		分类列表,可多个
		wp:term_id:自增序号,且分类和标签用的是同一个
		wp:category_nicename:URL友好名称,作为相关URL的一部分
		wp:category_parent:父分类,无即为空
		wp:cat_name:显示的分类名称
	-->

	<wp:tag><wp:term_id>2</wp:term_id><wp:tag_slug>tag_test</wp:tag_slug><wp:tag_name>< ![CDATA[标签测试]]></wp:tag_name></wp:tag>
	<!--
		标签列表,可多个
		wp:term_id:自增序号,与标签使用同一个序列
		wp:tag_slug:URL友好名称,作为相关URL的一部分
		wp:tag_name:显示的标签名称
	-->

	<generator>http://wordpress.org/?v=3.1.3</generator><!--WXR文件生成工具的标识-->

	<item><!--页面或者日志内容,每个为一个item-->
		<title>Title</title>
		<!--标题-->
		<link>http://blog.example.com/title/</link>
		<!--URL地址-->
		<pubdate>Thu, 15 Apr 2010 23:20:03 +0000</pubdate>
		<!--发布时间-->
		<dc:creator>admin</dc:creator>
		<!--文章作者-->
		<guid isPermaLink="false">http://blog.example.com/?page_id=1</guid>
		<!--
			GUID 意为 Global Unique IDentification,即全局唯一标识
			isPermaLink="false" 指示该地址非合法URL地址的属性
		-->
		<description></description>
		<content:encoded>< ![CDATA[Content_test_1]]></content:encoded>
		<!--这里是正文内容-->
		<excerpt:encoded>< ![CDATA[]]></excerpt:encoded>
		<!--文章摘录,供RSS/Atom使用,一般为空-->
		<wp:post_id>2</wp:post_id>
		<!--页面或日志的序号,两者使用同一序列-->
		<wp:post_date>2012-12-21 07:59:5</wp:post_date>
		<!--发表时间-->
		<wp:post_date_gmt>2010-12-20 23:59:59</wp:post_date_gmt>
		<!--发表时间(GMT)-->
		<wp:comment_status>open</wp:comment_status>
		<!--评论开启情况,open / closed-->
		<wp:ping_status>closed</wp:ping_status>
		<!--Ping开启情况,open / closed-->
		<wp:post_name>blog_title</wp:post_name>
		<!--URL友好的名称-->
		<wp:status>publish</wp:status>
		<!--页面或日志状态,publish / draft / pending / private-->
		<wp:post_parent>0</wp:post_parent>
		<!--只用于页面,指示父页面的id-->
		<wp:menu_order>0</wp:menu_order>
		<!--只用与页面,作为导航时的排序权值-->
		<wp:post_type>post</wp:post_type>
		<!--文章类型,post / page-->
		<wp:post_password></wp:post_password>
		<!--文章是否加密-->
		<wp:is_sticky>0</wp:is_sticky>
		<!--文章是否置顶,0 / 1-->

		<category domain="post_tag" nicename="tag_test">< ![CDATA[Tag Test]]></category>
		<category domain="category" nicename="category_test">< ![CDATA[Category]]></category>
		<!--
			日志或页面的标签和分类,可多个
			domain:标签对应post_tag,分类对应category
			nicename:对应标签或分类的URL友好名称
			<![CDATA[]]>:标签或分类的显示名称
		-->

		<wp:postmeta><!--日志或页面的元数据,可多个-->
			<wp:meta_key>_edit_last</wp:meta_key>
			<!--元数据的关键字-->
			<wp:meta_value>< ![CDATA[1]]></wp:meta_value>
			<!--元数据对应关键字的值-->
		</wp:postmeta>

		<wp:comment><!--评论,可多个-->
			<wp:comment_id>1</wp:comment_id>
			<!--自增序号,评论专用-->
			<wp:comment_author>< ![CDATA[anonymous]]></wp:comment_author>>
			<!--评论者用户名-->
			<wp:comment_author_email>anonymous@anonymous.com</wp:comment_author_email>
			<!--评论者邮箱-->
			<wp:comment_author_url>http://blog.anonymous.com</wp:comment_author_url>
			<!--评论者链接-->
			<wp:comment_author_ip>8.8.8.8</wp:comment_author_ip>
			<!--评论者IP-->
			<wp:comment_date>2012-12-21 07:59:59</wp:comment_date>
			<!--评论时间-->
			<wp:comment_date_gmt>2012-12-20 23:59:59</wp:comment_date_gmt>
			<!--评论时间(GMT)-->
			<wp:comment_content>< ![CDATA[Content of Comment]]></wp:comment_content>
			<!--评论内容-->
			<wp:comment_approved>1</wp:comment_approved>
			<!--评论是否被允许-->
			<wp:comment_type></wp:comment_type>
			<!--评论类型,空白表示一般评论,否则会标记位pingback-->
			<wp:comment_parent>0</wp:comment_parent>
			<!--父评论,指定所回复的评论-->
			<wp:comment_user_id>0</wp:comment_user_id>
			<!--如果评论者为注册用户,这里会记录用户ID-->
		</wp:comment>
	</item>
</channel>
</rss>

参考:http://ipggi.wordpress.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/

A recommended kind of RSS solution

Today I want to recommend a kind of RSS solution and  it’s just what I use for my blog.

In this way, we will have a permanent and unique rss url. As for me, it’s http://feeds.huxuan.org/huxuan

1)Sign up as the same name for your feed in FeedSky & FeedBurner.

e.g. I have
http://feed.feedsky.com/huxuan for FeedSky &
http://feeds.feedburner.com/huxuan for FeedBurner
(I just have it for example, Please don’t subscribe my blog through this two address)

2) Use the Domain Binding Service which Feedburner & Feedsky both provide to host the feed by your own domain name

You should choose only one of the two & Feedburner is recommended absolutely
You need to create a CNAME entry in the DNS records here
More information are provided by Feedburner & Feedsky when you configure the Domain Binding Service

3) Change the feed source you didn’t choose in step 2

e.g. I choose Feedburner to create the feed, so I change the feed source of Feedsky just into http://feeds.huxuan.org/huxuan.

4)Change the default rss url of wordpress

In the header.php of theme we use, similar code can be found like this:

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="http://blog.huxuan.org/feed" />

Change the url with underline into the feed you have created.

5)Change all possible default feed url on the site

There may be many default feed url list on the site most presenting as a link of an image or some else.
Just search for it and change it!

Attention: Some Errors happen in Step 6. Ignore it now.

6)Redirect the default feed url to the new one just in case

Insert the code below to .htacess which located in the main directory
# redirect default feed url to the permanent one
Redirect /feed http://feeds.huxuan.org/huxuan

7)Now all steps is done, just share your unique & permanet feed url to your friends

if one of the two feed service providers don’t work, just change to the other one via repeating Step 2 & 3

P.S. If there’s any error or problem, please feel free to inform me of that.

About My Coding,My Study&My Life……

    开学两周了,来学校也一个月了,大一下半学期,来了,却又显得是那样突然……刚开学事很多,很久没更新日志,现在整个学期的大致轨迹已基本确定,在此略微描绘一下……

My Coding
    说来惭愧,菜鸟一个,随随便便就把”Coding”这个词套在了自己身上,确实没想到其他好的词,暂且误用一下吧。
    高级程序语言课还是C++,这学期主要讲类,不难,但觉得还是多学点,学深点好,毕竟我还想继续曾给我莫大遗憾的ACM。
    数据结构课,老师要考虑到大部分同学的,所以我暂时保留所有的评价了。不过让我纠结的是一定要用C语言,不得不拾起这块鸡肋,多学点没坏处,只能这样安慰自己了。
    在MSTC的Silverlight组,虽然本人审美观几乎可以忽略,但还是试图激发一下自己的潜力吧。这学期GC也说要开不少讲座的,网页开发,数据库之类,主要还是那个令我很纠结的词——C#,要学的,迟早要学的……
    另外,在MSTC里面跟着另外一个学长学着做校内应用,JAVA、JavaScript、Jsp、CSS,能来的应该都来了吧,貌似还很齐了……
    虽然刚来学校的时候,一位学长告诫了我面对技术性社团的态度,我希望还是能真正学到点东西吧……
    IDE从DEV到VC,接着是VS,再到即将使用的eclipse,别人一直说语言学的多反而不好,专一才是正道。那句话更多是一个借口吧,以鄙人现在的水平,学的都是一些最最基础的东西,乘着还能熬夜,多学点没坏处吧。这学期想试试以做带看,少看点书,多做点东西,哪怕是简单的,希望效果能好一点……

My Study
    学校的课程就没什么好说的,“该撬的不该撬的只要能撬都得撬”,这是鄙人总结出来的,仅供参考。“必修课选撬,选修课必撬”,这是从学长那听来的。
    找过辅导员了,看了上学期的排名,勉强20,只能说是报应,一个星期学一个学期的东西,活该考不好……
    找过教务处了,说我们这学期可以报四级(本来说B班大二上考,C班大二下考),还得知我们上学期不能报四级的根本原因是没有电子照片,彻底无语了,铁定报了,迟早要裸奔的……
    英语除了四级,还有TOEFL和GRE,虽然我不一定走出国这条路,但还是觉得应该经历一下这个过程。学长说早准备有把握,朋友说早准备用处不大,我就以准备四级的心态带着准备吧,其实也就是背背单词,听听听力,读读文章之类的,尽量多说点吧,我真正希望提高的还是能力……
    另外,我还去了主楼204——数学第二学位办公室,已经开课了,我错过了报名时间,但还是去碰碰运气。上午到的,没人,等在门口,背背单词。背倦了,还没看到老师,就写了张纸条从门缝里塞了进去……主要留下了我等半天的事实和手机号码。上午没带手机,中午看的时候,发现了预感到的未接电话,好事多磨吧,我能感觉到那信号就是从那里发出来的……下午先去健身的,然后才去,终于见到老师了,很热情,应该是被我感动的吧,补报名成功,只是叫我自己补落下的课。事后才发觉当时的做法是完全正确的,虽然现在自己都觉得有点假……为期两年,每周8学时,周六周日的晚上6点到10点,每学期两门课,需要至少过6门,这学期是数值分析和运筹学,也就意味着我必须用极短的时间把正在上的高数下和线代都自学完,我知道,有我玩的了……

My Life
    应该没有太多人关心我的生活吧,还是简要说说吧。
    健身,北航的新健身馆条件比我想象的要好,现在就是人多点,以后会好的吧。人越来越少,这是健身房不变的定律。我会争取每天都去的,当然有氧和无氧的要穿插一下,锻炼和减肥并举……
    电脑,一直说要远离这个“时间老虎机”的,但是一直效果不够理想……现在双管齐下了:事情真的多了,逼逼自己,不知道是对是错;多些时间泡在图书馆、自习室、实验室,这样应该也会有所改观吧?
    另外是生活作息,尽量有点规律吧,争取在12点左右睡觉,上午7点之前起床。当然这些还都处于未能实现的理想状态,尽力去追求吧。

Summarizes
    我的大一下应该基本就是在这些轨迹中运行吧,不知是前进、后退还是徘徊。有很多都是尝试,当然目的都还算比较明确的,我只能说:希望可以……