好友
阅读权限20
听众
最后登录1970-1-1
|
本帖最后由 小心boss 于 2020-3-19 09:09 编辑
刚好自己要用,网上搜了下好像没有能正常用的。修修补补了一下。
亲测正常使用,人懒没办法,什么都想偷懒。。。。
[Python] 纯文本查看 复制代码 class wordpress_post:
def __init__(self, tittle, content):
self.tittle = tittle
self.content = content
self.postname = parse.quote(str(tittle))
def mysql_con(self):
conn = pymysql.connect(host='www.123', port=3306, user='w123', passwd='EX123RyB',
db='w12312123, charset='utf8') # 在此修改数据库信息
return conn
def up(self):
times = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
sql = "INSERT INTO tu_posts(post_author,post_date,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_name,to_ping,pinged,post_modified,post_content_filtered,post_parent,menu_order,post_type,comment_count) VALUES ('1','%s','%s','%s','','publish','open','open','%s','','','%s','','0','0','post','0')" % (
str(times), str(self.content), str(self.tittle), self.postname, str(times))
return sql
def cat(self, ids, cat):
sql = "INSERT INTO tu_term_relationships(object_id,term_taxonomy_id,term_order) VALUES (%s,%s,'0')" % (ids, cat)
return sql
def close_mysql(self, cursor, conn):
conn.commit()
cursor.close()
conn.close()
[Python] 纯文本查看 复制代码 def post_article(info, tittle):
with open('temp/log.txt', 'a+') as f:
f.write(str(info) + 'n')
with open('temp/temp.txt', 'r') as f:
wz_content = f.read()
os.remove('temp/temp.txt')
a = wordpress_post(str(tittle[0]), wz_content)
conn = a.mysql_con()
cursor = conn.cursor()
c = a.up()
effect_row = cursor.execute(c)
new_id = cursor.lastrowid
d = a.cat(new_id, '1')
effect_row = cursor.execute(d)
a.close_mysql(cursor, conn) |
|