clmemo を blog に投稿
社内ブログっていうのがあるのですが
あんまり書くことありません><
でも、社内にとじてるから秘密っぽいことも
書けるかも!!!
やっぱり書く事ありませんでした
だから、ChangeLogメモを投稿しちゃうようにしました。
秘密の事書いても大丈夫だしね!!
#!/usr/bin/env python # -*- coding: utf-8 -*- end_point = 'http://foo.com/xmlrpc' username = 'dankogai' password = 'kogaidan' clmemo = '/home/yoshiori/clmemo.txt' def publish_entry(title, text): import xmlrpclib server = xmlrpclib.Server(end_point) entry_id = server.metaWeblog.newPost( '1', username, password, {'title': title, 'description': text}, xmlrpclib.True) def read_changelog(file_path): import re p = re.compile('\d{4}-\d{2}-\d{2}') changelog = {} data = [] item = {} for line in open(file_path): if line.startswith('^L'): break if not line.startswith('\t'): if line.strip(): if p.match(line.split()[0]): data = [] changelog[line.split()[0]] = data else : if line.startswith('\t*'): body = line[line.index(':') + 1:].strip() item = {'title' : line[2:line.index(':')].strip(), 'body' : body} data.append(item) else: item['body'] += line.strip() return changelog if __name__ == "__main__": import datetime changelog = read_changelog(clmemo) yesterday = datetime.date.today() - datetime.timedelta(days=1) for date,data in changelog.iteritems(): if yesterday.isoformat() == date: for item in data: title = item['title'] body = item['body'] publish_entry(title,body)
こんなのを一日一回、cron で動かしてます><