昨天和集训队的几位大大聊天,聊着聊着就聊到了博客的问题,发现几个人要么在CSDN 要么在博客园上, 要记住他们的所有的地址还真是不便,于是灵机一动,何不自己写一款小工具来存储打开他们的博客呢?于是将这款工具取名为iiblogs,意为ii系列的博客工具,其实本质上就是个收藏夹,打开某位大牛博客的方法就是直接终端下输入:iiblogs [大牛的名字] 。

各种操作比如添加,删除,修改,改名都可以在使用选项来完成,比如

增加-a --add

删除-d --del

修改-m --modify

改名-c --change

考虑到锻炼自己的原因,存储结构选择了MySQL,虽说大材小用,但对程序总体的性能和稳定性上贡献还是比较大的。

下面给出代码:

MySQL 建库语句(考虑到中文存储问题,默认utf8):

drop database if exists iiblogs;

CREATE DATABASE iiblogs DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use iiblogs; create table blogs
(
id int unsigned auto_increment primary key,
name varchar(50) not null,
address varchar(100) not null
);
 #!/usr/bin/python
#coding=utf-8
#python 2.7.6 import MySQLdb
import sys
import getopt
import os HOST = 'localhost'
USER = 'root'
PASSWORD = '×××××××'
DBNAME = 'iiblogs' BROWSER = 'chromium-browser' def Usage():
print "iiblogs [name] | [option] [name]"
print "\tiiblogs [name] open his blog"
print '\tiiblogs [-a|--add] [name] add new address'
print '\tiiblogs [-d|--del] [name] delete address'
print '\tiiblogs [-m|--modify] [name] modify the address'
print '\tiiblogs [-c|--change_name] [newname] change the name'
print '\tiiblogs [-l|--list] list all'
print '\tiiblogs [-h|--help] help infomation'
return def Connect():
conn = MySQLdb.connect(host=HOST, user=USER, passwd=PASSWORD, db=DBNAME, charset = 'utf8')
return conn def Add(name):
conn = Connect()
mycursor = conn.cursor()
sql = "select name from blogs where name = %s"
param = (name)
n = mycursor.execute(sql, param)
if n > 0:
print 'This name exists'
return
addr = raw_input("blog's address:")
sql = "insert into blogs values(null, %s, %s);"
param = (name, addr)
mycursor.execute(sql, param)
conn.commit()
conn.close()
return; def Delete(name):
conn = Connect()
mycursor = conn.cursor()
sql = "delete from blogs where name = %s"
param = (name)
mycursor.execute(sql, param)
conn.commit()
conn.close()
return; def Opensite(args):
conn = Connect()
mycursor = conn.cursor()
sql = "select address from blogs where name=%s"
weblist = []
fail = []
webs = ' '
for name in args:
param = (name)
n = mycursor.execute(sql, param)
if n < 1:
print "'%s' does not exist" % (name)
fail.append(name)
continue
else:
print "'%s' OK." % (name)
for one in mycursor.fetchone():
one = one.encode("utf-8") #utf8 ------------
weblist.append(one)
if (len(weblist) == 0):
return
for index, item in enumerate(weblist):
webs = webs + ' ' + item
last = BROWSER + webs + ' &'
os.system(last)
conn.close()
return def List():
conn = Connect()
mycursor = conn.cursor()
sql = "select name, address from blogs"
mycursor.execute(sql)
for res in mycursor.fetchall():
print res[0], ': ', res[1]
conn.close()
return def Modify(name):
conn = Connect()
mycursor = conn.cursor()
sql = 'select name from blogs where name=%s'
param = (name)
n = mycursor.execute(sql, param)
if n < 1:
print "This name does not exist"
return
new = raw_input("please input the new address:")
sql = "update blogs set address=%s where name=%s"
param = (new, name)
mycursor.execute(sql, param)
conn.commit()
conn.close()
return def Changename(name):
conn = Connect()
mycursor = conn.cursor()
sql = 'select name from blogs where name=%s'
param = (name)
n = mycursor.execute(sql, param)
if n < 1:
print "This name does not exist"
return
new = raw_input("please input the new name:")
sql = "update blogs set name=%s where name=%s"
param = (new, name)
mycursor.execute(sql, param)
conn.commit()
conn.close()
return try:
opts, args = getopt.getopt(sys.argv[1:], 'lha:d:m:c:', ['list', 'help', 'add', 'del', 'modify', 'change'])
except getopt.GetoptError:
Usage()
sys.exit()
for o, a in opts:
#a = a.decode("gbk").encode("utf-8")
if o in ('-h', '--help'):
Usage()
sys.exit()
if o in ('-a', '--add'):
Add(a)
sys.exit()
if o in ('-d', '--del'):
Delete(a)
sys.exit()
if o in ('-l', '--list'):
List()
sys.exit()
if o in ('-m', '--modify'):
Modify(a)
sys.exit()
if o in ('-c', '--change'):
Changename(a)
sys.exit()
if len(args) == 0:
Usage()
else:
Opensite(args)

【Python】iiblogs ——命令行下的网页收藏夹的更多相关文章

  1. [兴趣使然]用python在命令行下画jandan像素超载鸡

    下午刷煎蛋的时候看到 Dthalo 蛋友发的系列像素超载鸡,就想自己试试用python脚本画一个,老男孩视频里的作业真没兴趣,弄不好吧没意思,往好了写,自己控制不好,能力不够. 所以还是找自己有兴趣的 ...

  2. Ubuntu:命令行下浏览网页

    前述 兴起,试一下不用图形化界面浏览 安装w3m 直接进入root账号 apt-get install w3m 检验是否成功 w3m www.baidu.com 就这样成功的进入baidu了,纯文本模 ...

  3. ubuntu 命令行下查看网页 w3m

    w3m localhost/index.php

  4. window的cmd命令行下新增/删除文件夹及文件

    新增文件夹 (md / mkdir) md <folderName>: folderName 就是文件路径,只输入文件夹名称时表示在当前目录下创建文件夹. 比如:md F:\test\pr ...

  5. Windows命令行下pip安装python whl包

    因为做网页爬虫,需要用到一个爬新闻的BeautifulSoup 的包,然后再关网上下的是whl包,第一次装,虽然花了点时间,最后还是装上去了,记录一下,方便下次. 先发一下官方文档地址.http:// ...

  6. python命令行下tab键补全命令

    在python命令行下不能使用tab键将命令进行补全,手动输入又很容易出错. 解决:tab.py #/usr/bin/env python # -*- coding:utf-8 -*- ''' 该模块 ...

  7. Python安装后在CMD命令行下出现“应用程序无法启动.............”问题

    问题存在之一:系统是刚刚重做的精简版服务器系统(阉割版) AN就是在阿里云上刚开的Windows Server 2008 系统上碰到的  吓尿了都 症状:            正常安装python环 ...

  8. 【Python】iichats —— 命令行下的局域网聊天程序

    转载请声明出处:http://www.cnblogs.com/kevince/p/3941728.html   ——By Kevince ii系列工具第三弹,命令行下的局域网聊天程序 原理: 程序启动 ...

  9. 命令行下查看python和numpy的版本和安装位置

    命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...

随机推荐

  1. Sql Server专题:SQL 经典实例

    SQL 经典实例 1.实例表: Student(S#,Sname,Sage,Ssex) 学生表 S#:学号:Sname:学生姓名:Sage:学生年龄:Ssex:学生性别 Course(C#,Cname ...

  2. android textView 富文本显示

    String parenName = entity.getParent().getMember_nickname(); parantNameRich = "<font color='# ...

  3. 映射 SQL 和 Java 类型

    http://alex2009.blog.51cto.com/749524/272942 AJAX: http://www.w3school.com.cn/jquery/ajax_ajax.asp h ...

  4. grok 正则解析日志例子<1>

    <pre name="code" class="html">下面是日志的样子 55.3.244.1 GET /index.html 15824 0. ...

  5. HDOJ-1007 Quoit Design(最近点对问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 给出n个玩具(抽象为点)的坐标 求套圈的半径 要求最多只能套到一个玩具 实际就是要求最近的两个坐标的距离 ...

  6. smb相关资料

    smb相关资料 看资料就上维基 https://en.wikipedia.org/wiki/Server_Message_Block#Implementation http://www.bing.co ...

  7. [每日一题] 11gOCP 1z0-052 :2013-09-19 创建用户...................................................B41

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11834661 正确答案:BC 这道题比较简单,我就以答案来解析,如下来自官方文档创建用户的 ...

  8. 热烈祝贺Polymer中文组织站点上线

    欢迎来到前端世界的明天 由于官网被墙, 所以 http://docs.polymerchina.org/ 其实是一件很有意义的事. 组件化和重用,一直是编程界几十年来前进的方向和目标,随着时间的推移和 ...

  9. ORA-03113 通信通道的文件结尾(ORA-19804 ORA-16038-归档空间满的处理方法)

    1.数据库启动报错SQL> startupORACLE 例程已经启动. Total System Global Area 1887350784 bytesFixed Size 2176848 b ...

  10. ORACLE 主要后台进程1

    Oracle Database Background Processes: 1.Database writer (DBWn)The database writer writes modified bl ...