0%

数据库操作wordpress

数据库操作wordpress

QQ群:397745473

1
2
3
4
5
6
7
8
参考:
Python操作WordPress数据库发布文章
http://www.snailtoday.com/archives/14029
https://raspberrypi.club/41.html
https://www.emperinter.info/2020/05/21/python-wordpress-xmlrpc/

WordPress加密某个分类的所有文章:
https://www.ludou.org/wordpress-encrypt-all-articles-of-a-category.html
1
pip3 install PyMySQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class wordpress_post:
def __init__(self,tittle,content):
self.tittle=tittle
self.content=content
def mysql_con(self):
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='pwd', db='wordpress', charset='utf8') #将这里换为你的数据库地址
return conn
def up(self):
times=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
sql="INSERT INTO wp_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),str(self.tittle),str(times))
return sql
def cat(self,ids,cat):
sql="INSERT INTO wp_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()
1
2
3
4
5
6
7
8
9
10
11
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='pwd', db='wordpress', charset='utf8') #将这里换为你的数据库地址

a=wordpress_post(str(t),wz_content) #这里第一个参数是标题 第二个是文章内容
conn=a.mysql_con()
cursor = conn.cursor()
c=a.up()
effect_row = cursor.execute(c)
new_id = cursor.lastrowid #这里是记录文章id以便设置文章的分类
d=a.cat(new_id,'1')
effect_row = cursor.execute(d)
a.close_mysql(cursor,conn)

wordpress的分类目录牵涉到下面两个表:

1
2
wp_terms:存储每个目录、标签
wp_term_relationships:存储每个文章、链接和对应分类的关系

QQ群:397745473

欢迎关注我的其它发布渠道