2017-08-31
暑假结束了
忙碌的两个月
我觉得大部分家长是不喜欢孩子放暑假这件事情的。孩子放假的时候,我不希望她整天在外婆家,就把她带到我们自己的家里。
这个夏天,7月份特别热。我给孩子报了游泳班,为期两个星期。天天早上骑着自行车,顶着个大太阳,把她送到游泳馆。到10点多钟再接回家,急急忙忙做午饭。
夏天里我还给小孩报名学了一个沙画。在我家隔壁的小红花艺术培新中心。那是常州电视台下属的一个培训中心。女儿因此还被采访了,前几天在电视上看到了她。
暑假里的晚上,我们去了好多次市民广场。女儿在那里学着玩轮滑。我也去练习了两次。第一次摔得我屁股好疼。慢慢找到了一点感觉。
女儿的钢琴还好没有荒废。每天练琴,没有落下。
假期里去茅山玩了一次。那一天实在是太热了。
没有出去旅游。茅山应该不算,那里比较近,开车一个多小时就到了。
房子
弟弟卖了房。幸好他在卖房之前又买了一套。因为顶不住还贷款的压力,卖出去了手里的一套。短短两年时间,房子升值的钱已经足够他结婚的开支了。在飞涨的房价面前,工资收入显得特别的微不足道。
最近常州的房价也涨得厉害。前几天银行通知我们贷款已经还完了。可是现在的房子我们也买不起了,存款留在口袋里就是贬值,真不知道改怎么处理。
昨天听吴晓波频道里面聊到95后,说95后的年轻人沉迷于二次元。原因就是他们很难在现实生活中找到快乐。这一代年轻人想要去买房何其困难啊。
欣慰的事情
老婆终于不打游戏了!
老婆终于不打游戏了!
老婆终于不打游戏了!
这件事情真值得弹冠相庆。
女儿在暑假里没有生病。丈母娘感觉喉咙里面堵着一个东西,昨天CT检查结果说是一个息肉,没有大碍。家里人都很健康。老婆的体重应该快到历史新高了。
我暂时还没有失业。P陈介绍的项目我在做着,但是还没和客户说好收多少钱。
用代码写简书
简书的浏览器体验其实挺不错的。以前我有一堆markdown文件,放在github上面做日记。今天我就在折腾怎么把这些文件上传到简书。其实一篇一篇手工贴也不是多麻烦的事情,但是身为程序员,我总想着用代码来解决。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import time
import json
import requests
import browsercookie
import bs4
class JianshuClient(object):
def __init__(self):
self.cookie = browsercookie.firefox()
self.session = requests.Session()
# try to get the csrf token
url = "http://www.jianshu.com/writer"
r = self.session.get(url, cookies=self.cookie)
soup = bs4.BeautifulSoup(r.content, "lxml")
meta = soup.findAll("meta")
for e in meta:
name = e.attrs.get("name", "")
if name == "csrf-token":
self.csrf_token = e.attrs.get("content")
break
self.headers = {
"Origin": "http://www.jianshu.com",
"Referer": "http://www.jianshu.com/writer",
"x-writer-version": "12",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-Token": self.csrf_token
}
self.articles = []
def list_notebooks(self):
"""
:return list: list of notebooks. Example is:
[
{
"created_at": "2015-10-07T15:16:31.000+08:00",
"deleted_at": null,
"has_update_at": 1464522367,
"id": 2052563,
"last_published_at": 1464522367,
"likes_count": 0,
"name": "\u65e5\u8bb0\u672c",
"seq": null,
"updated_at": "2016-05-29T19:46:07.000+08:00",
"user_id": 1009135
},
{
"created_at": "2015-10-07T15:16:31.000+08:00",
"deleted_at": null,
"has_update_at": 0,
"id": 2052564,
"last_published_at": null,
"likes_count": 0,
"name": "\u968f\u7b14",
"seq": null,
"updated_at": "2015-10-07T15:16:31.000+08:00",
"user_id": 1009135
}
]
In the data, field "id" is important.
"""
url = "http://www.jianshu.com/writer/notebooks"
result = self.session.get(url, cookies=self.cookie)
return result.json()
def new_article(self, notebook_id):
"""
:return dict: article returned by jianshu. Example:
{
"note_type" : "markdown",
"id" : 16511092,
"last_compiled_at" : 0,
"notebook_id" : 2052563,
"seq_in_nb" : -5,
"autosave_control" : 0,
"content_size_status" : "fine",
"title" : "无标题文章",
"content" : "",
"slug" : "877f75fe8cfd",
"content_updated_at" : 1504159184,
"shared" : false
}
In the data, field "id" is important.
"""
url = "http://www.jianshu.com/writer/notes"
request_data = {
"id": "c-5",
"notebook_id": notebook_id,
"seq_in_nb": 0 - len([x for x in self.articles
if x['notebook_id'] == notebook_id])
}
result = self.session.post(url, json=request_data, headers=self.headers)
return result.json()
def list_articles(self):
"""
:return list: list of articles. Example:
[ {u'autosave_control': 0,
u'content_size_status': u'fine',
u'content_updated_at': 1504159184,
u'deleted_at': None,
u'id': 16511092,
u'last_compiled_at': 0,
u'note_type': u'markdown',
u'notebook_id': 2052563,
u'seq_in_nb': -5,
u'shared': False,
u'slug': u'877f75fe8cfd',
u'title': u'\u65e0\u6807\u9898\u6587\u7ae0'}]
"""
url = "http://www.jianshu.com/writer/notes"
result = self.session.get(url, headers=self.headers)
self.articles = result.json()
return self.articles
def get_article_content(self, article_id):
"""
:return dict: content. Example:
{"content": "xxx"}
"""
url = "http://www.jianshu.com/writer/notes/{0}/content".format(article_id)
result = self.session.get(url, headers=self.headers)
return result.json()
def update_article(self, article, title, content):
"""
Update an article.
:param dict article: article object. Can be in the output of
`new_article` or `list_articles`
:param str slug: Also can be found in article object
:param str title: article title
:param str content: content in markdown format
"""
url = "http://www.jianshu.com/writer/notes/{0}".format(article["id"])
request_data = {}
request_data.update(article)
request_data["title"] = title
request_data["content"] = content
request_data["content_updated_at"] = int(time.time())
request_data["autosave_control"] = int(article.get("autosave_control", 0)) + 1
result = self.session.put(url, headers=self.headers, json=request_data)
return result.json()
def publicize(self, article):
"""
Make the article visible to public.
:param dict article: article object.
"""
url = "http://www.jianshu.com/writer/notes/{0}/publicize".format(article["id"])
result = self.session.post(url, headers=self.headers)
return result.json()
def main():
"""
Publish a markdown file to www.jianshu.com.
It requires that you have logged into www.jianshu.com from firefox.
"""
filename = sys.argv[1]
if not os.path.exists(filename):
raise Exception("File {0} not exist".format(filename))
title = os.path.basename(filename).split('.')[0]
content = open(filename).read()
j = JianshuClient()
notebooks = j.list_notebooks()
new_article = j.new_article(notebooks[0]["id"])
j.update_article(new_article,
title,
content)
j.publicize(new_article)
if __name__ == '__main__':
main()
这是我今天写出来的一个小程序。分分钟搞定文章上传。