导入旧评论到多说

2016-10-30 16:40:00

趁周末有空+自己懒癌暂时没有发作,终于把最后2篇文章的迁移和评论的迁移弄好了。

不过写脚本弄评论迁移的时候发现,自己长久不写python,很多基础的东西又忘记了。

  1. 读excel用应该是xlrd,这个以前还真没用过,不过用的方法很简单。最大的问题是xlrd的官网上不去()。不过用法倒和xlwt没差多少
  2. datetime的用法又是各种查文档,看来这是一个习惯了,已经背不出了
  3. timedelta的用法同上
  4. json的dumps彻彻底底忘记了啊喂,记得当时用django写微信公众号后台还研究了好久unicode转换之类的
  5. 原来最后想直接输出到文件的,但是居然unicode报错而且我还不想再折腾了……直接从console拷贝了,幸好也只有14条评论,要是14亿条就吓人了(哈哈想想也不可能)
  6. 多说的parent_key是不能用还是我用错了格式……

代码记录如下:

#-*- coding: utf-8 -*-
import xlrd
import json
import datetime

result = {"posts": []}

data = xlrd.open_workbook('comments.xls')
table = data.sheets()[0]

nrows = table.nrows

for i in range(0, nrows):
    row_value = table.row_values(i)
    v = {
        "post_key": "post_%s" % int(row_value[0]),
        "author_name": row_value[1],
        "author_email": row_value[2],
        "created_at": (datetime.datetime.strptime(row_value[3], "%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"),
        "message": row_value[4],
        "thread_key": "/blog/post/%s" % int(row_value[5])
    }
    if not row_value[6] == 'NULL':
        v["parent_key"] = "post_%s" % int(row_value[6])
    result["posts"].append(v)

out = json.dumps(result, ensure_ascii=False)
print out

参考:

多说导入格式

python datetime参考(各种慢,直接去别人家的博客找了)

xlrd Github仓库(其实没看,也是去别人家的博客找了)

The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.

Using words.txt (right click and ‘Save Link/Target As…’), a 16K text file containing nearly two-thousand common English words, how many are triangle words?

Problem 41 Pandigital prime

2016-10-26 06:54:00

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.

What is the largest n-digit pandigital prime that exists?

觅食图集

2016-10-23 23:11:47

原来想自己用gimp弄个九宫格出来的,愣是发现gimp太(我)不(不)好(会)使(用)了,只能用了美图秀秀的在线版本工具出来,这么一整觉得自己好low啊……

小馄饨成为了最受我欢迎的早饭,张江手抓饼第二(没有拍但是我自己知道)烧麦第三

听说昨天早上github挂了,自从这个开始家里网络上github io就各种慢,好像被波及了?图片压缩成了jpg还是有大概3M大小,估计打开超级慢(如果其他人也被波及了的话),而且很模糊啊啊啊啊…………

想念微博的长微博工具

An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021…

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p ≤ 1000, is the number of solutions maximised?

Take the number 192 and multiply it by each of 1, 2, and 3:

\[192 × 1 = 192\] \[192 × 2 = 384\] \[192 × 3 = 576\]

By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)

The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).

What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, … , n) where n > 1?