我在Wordpress中有大约30,000个非常短的帖子。我使用SQLlite数据库和python脚本构建它们,并通过python中的wordpress_xmlrpc库上传它们。但是我的网站在100-200个帖子后发生故障,因为服务器认为这是一次DoS攻击。
我的服务器是一个我有SSH访问权限的linux盒子。我正在寻找一种方法,可以更直接地将帖子上传到Wordpress,例如直接与其数据库交互,或使用直接在服务器上发生的本地进程。任何人都可以提出任何想法吗?
答案 0 :(得分:4)
我试图通过Python脚本直接与数据库交互来做同样的事情,它对我来说就像一个魅力。我使用的是MySQL数据库。
为此,您需要ssh到托管Wordpress站点和数据库的服务器。并在那里运行以下脚本:
运行此脚本的必备条件:
一个。所有帖子都应该在一个单独的不同文件中 。目录
湾每个文件应包含第一行中的帖子标题和帖子内容 在其他方面。
#!/usr/bin/env python
import MySQLdb
import fnmatch
import os
#List to contain all the post files
my_match = []
#Gather post files in above list
for file in os.listdir("<path of the directory where post files remains>"):
if fnmatch.fnmatch(file, '.*'):
print(file)
continue
my_match.append(file)
print my_match
#Make database connection
conn = MySQLdb.connect(host= "localhost", user="<username>", passwd="<password>", db="<database name>")
x = conn.cursor()
print x
for fl in my_match:
new_file = "<path to the directory where post files remains>/" + fl
with open(new_file) as f:
heading = f.readline().strip()
content = f.read()
print heading
url = heading.replace(" ", "-")
print url
#try db query, change according to your database and tables
try:
x.execute("""INSERT INTO wp_posts (post_author, post_date, post_content, post_title, post_name) VALUES (3, "2017-03-28 20:24:12", %s, %s, %s)""",(content, heading, url))
conn.commit()
print "Done! :)"
except:
conn.rollback()
print "Oops, not done :("
conn.close()
答案 1 :(得分:0)
找到另一种方式,万一其他人偶然发现了这一点。将所有帖子转储到csv文件并使用“csv发布”小部件。我正在使用Ultimate CSV Importer Free。非常简单。