本代码纯粹是为了测试练习之用,费话不多说,直接上代码: 1#!/usr/bin/python 2#coding=utf-8 3#Author by 361way.com 4import time 5import urllib3 6import re 7import MySQLdb 8def Gtag_ID(db,tags): 9 tag_list = [100] 10 for tag in tags: 11 cursor = db.cursor() 12 id_qsql = "SELECT term_id FROM wp_terms where name=%s " 13 count = cursor.execute(id_qsql,tag) 14 if count == 0: 15 try: 16 sql = "INSERT into wp_terms (name,slug,term_group) values (%s,%s,0)" 17 data = (tag,tag) 18 cursor.execute(sql,data) 19 db.commit() 20 tag_id = cursor.lastrowid 21 print 'Add the new tag %s ,tag_id is ' %(tag),type(tag_id) 22 tag_list.append(int(tag_id)) 23 taxonomy_sql = "INSERT into wp_term_taxonomy (term_id,taxonomy,description) values (%s,'post_tag','') " % (tag_id) 24 #tax_data = (tag_id,'post_tag','',0,0) 25 cursor.execute(taxonomy_sql) 26 db.commit() 27 except: 28 db.rollback() 29 db.close() 30 else: 31 id……
Continue reading