Hexo-blogs-to-add-search-and-the-python-scripts-record-automatically
2016-11-09 17:50
429 查看
title: hexo博客添加搜索以及各自动python脚本记录
date: 2016/10/18 20:46:25
description: hexo博客添加搜索以及各自动python脚本记录,使用的是hexo-generator-search插件.
tags:
- python
- hexo
categories: python
https://github.com/PaicHyperionDev/hexo-generator-search
安装好之后,如果你的笔记文件是中文名的话,应该不会搜出结果,使用浏览器查看search.xml文件会报错,导致不能搜索
解决方法:将中文文件名全部转成英文命名的文件,文件太多,写了一个py脚本自动讲中文文件名转换成英文文件名,执行前请做好备份,确认电脑py2.7环境正常,其中注意修改文件路径
修改好之后,还要注意文件名也要不包含特殊字符
date: 2016/10/18 20:46:25
description: hexo博客添加搜索以及各自动python脚本记录,使用的是hexo-generator-search插件.
tags:
- python
- hexo
categories: python
hexo博客添加搜索以及各自动python脚本记录
小五游侠 2016-10-18 16:21:16hexo搜索
使用的是hexo-generator-search插件,安装方法见https://github.com/PaicHyperionDev/hexo-generator-search
安装好之后,如果你的笔记文件是中文名的话,应该不会搜出结果,使用浏览器查看search.xml文件会报错,导致不能搜索
解决方法:将中文文件名全部转成英文命名的文件,文件太多,写了一个py脚本自动讲中文文件名转换成英文文件名,执行前请做好备份,确认电脑py2.7环境正常,其中注意修改文件路径
# -*- coding: cp936 -*- import os import json import urllib import urllib2 import sys from urllib import quote path = 'E:\\Desktop\\files\\nodejs\\hexoBlog\\source\\_posts' class Youdao: def get_translation(self,words): url = "http://fanyi.youdao.com/openapi.do?keyfrom=testappccw01&key=1820729705&type=data&doctype=json&version=1.1&q=" url = url+urllib.quote(words.decode(sys.stdin.encoding).encode('utf8')) result = urllib2.urlopen(url).read() json_result = json.loads(result) json_result = json_result["translation"] return json_result[0] youdao = Youdao() for file in os.listdir(path): if os.path.isfile(os.path.join(path,file)) and len(file.split('.md'))>0: newname=(youdao.get_translation(file.split('.md')[0])+'.md').replace(' ','-') os.rename(os.path.join(path,file),os.path.join(path,newname)) print newname,'ok' print file,'ok'
修改好之后,还要注意文件名也要不包含特殊字符
创建Hexo笔记脚本
每次新建笔记都需要修改文件格式,很麻烦,下面这个脚本可自动创建文件并且重命名英文文件名,生成hexo格式的笔记文件,使用markdown pad2打开,注意markdown软件的路径#!/usr/bin/env python # -*- coding: utf-8 -*- # encoding=utf8 import sys import codecs import os import json import urllib import urllib2 import time from urllib import quote path = os.path.abspath('.') class Youdao: def get_translation(self,words): url = "http://fanyi.youdao.com/openapi.do?keyfrom=testappccw01&key=1820729705&type=data&doctype=json&version=1.1&q=" #url = url+urllib.quote(words.decode(sys.stdin.encoding).encode('utf8')) url = url+urllib.quote(words.encode('utf8')) result = urllib2.urlopen(url).read() json_result = json.loads(result) json_result = json_result["translation"] return json_result[0] youdao = Youdao() title = raw_input("Please input a title: ").decode(sys.stdin.encoding) tags = raw_input("Please input a tags(split by -): ").decode(sys.stdin.encoding) category = raw_input("Please input a category: ").decode(sys.stdin.encoding) newname=(youdao.get_translation(title)).replace(' ','-')+'.md' file=codecs.open(newname,"w","utf-8") print newname,'ok' file.write("---") file.write("\r\n") file.write("\r\n") file.write("title: "+title) file.write("\r\n") file.write("tags: ") file.write("\r\n") tags2 = tags.split("-") for item in tags2: file.write(" - "+item) file.write("\r\n") print item file.write("categories: "+category) file.write("\r\n") file.write("\r\n") file.write("---") file.write("\r\n") file.write("\r\n") file.write("\r\n") file.write("\r\n") file.write("<!--more-->") file.write("\r\n") file.write("\r\n") file.write("## "+title+" ##") file.write("\r\n") file.write("\r\n") file.write("-----------") file.write("\r\n") file.write("\r\n") file.write(u"*[小五游侠](http://895474150.qzone.qq.com)* ") file.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) file.write("\r\n") file.write("\r\n") file.close() os.system("G:\dev-software\mardown2.4.2\MarkdownPad2.exe "+path+"\\"+newname) print "D:\my file\dev-software\mardown2.4.2\MarkdownPad2.exe "+path+"\\"+newname raw_input("any key quit.")
上传更新coding page
自动上传更新py脚本,注意博客文件所在路径import os import sys p = os.popen('hexo clean',"r") while 1: line = p.readline() if not line: break print line p = os.popen('hexo g',"r") while 1: line = p.readline() if not line: break1 print line ss = raw_input("local server or deploy(1 or 2): ").decode(sys.stdin.encoding) if ss == '1': p = os.popen('hexo s',"r") while 1: line = p.readline() if not line: break print line if ss == '2': p = os.popen('hexo d',"r") while 1: line = p.readline() if not line: break print line
相关文章推荐
- 用Python和OpenCV创建一个图片搜索引擎的完整指南 The complete guide to building an image search engine with Python and
- Gridview之RowCommand,ButtonField[add buttons and use the RowCommand event to add custom functionality to the control]
- Add/Subtract Days to a Date and pass to a Record Object
- Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
- createDataSource, and add new rows on the datagrid to be filled out.
- Add, Remove, and Search Packages in Python with pip
- Get to the Top on Google: Tips and Techniques to Get Your Site to the Top of the Search Engine Ranki
- BOM API - uses the BOM_BO_PUB.PROCESS_BOM API to create bill header and add components to the bill
- how to play music and record from the mic at the same time?
- 70-216 Q253 Add the IAS server to the RAS and IAS Servers domain local group
- Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically a
- How to add a user and set environments for the us
- How to search a table in a store proc and open the store proc
- add cool toolbar 256corler is easy,only two file and onCreate func is needed also the MainFrame.toolbar must resize to what real need and also the load width is same to it.
- [Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?
- state-of-the-art implementations related to visual recognition and search
- [Drupal] How to add the js file and js code block in Drupal
- Using the full potential of Jython to build compact and maintainable wsadmin scripts
- SimpleCV install and "You need the python image library to save by filehandle"
- Import the Add Email and Post Configuration to the SiteMap managed solution -Dynamices CRM