python怎么讲整理好的文章直接发布到帝国cms里面呢,python会,帝国cms是php不会啊,找万能的搜索,果然找到了大神写的接口,测试了一下,非常完美,记录一下,以后用得着。
python发布文章到帝国cms接口模块
接口上传至/e/admin/中
fabu.php
<?php
/********密码验证***********/
$password='888'; //这个密码是登陆验证用的.您需要在模块里设置和这里一样的密码....注意一定需要修改.
if($password!=$_GET['pw']) exit('验证密码错误'); //安全检测,密码不符则退出
/****以下代码非专业人员不建议修改***************/
define('EmpireCMSAdmin','1');
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require LoadLang("pub/fun.php");
require("../class/delpath.php");
require("../class/copypath.php");
require("../class/t_functions.php");
require("../data/dbcache/class.php");
require("../data/dbcache/MemberLevel.php");
//获取分类列表
foreach($class_r as $kv)
{
if($kv['modid']=='1')//这个是分类所在的系统模型id,记得修改
{
$cates[]=array('cname'=>$kv['classname'],'cid'=>$kv['classid'],'pid'=>$kv['bclassid']);
}
}
if(empty($_POST))
{
//这里刷新列表
echo "<select name='list'>";
echo maketree($cates,0,'');
echo '</select>';
exit();
}
$link=db_connect();
$empire=new mysqlquery();
//验证用户
$loginin=$_POST['username'];
$lur=$empire->fetch1("select * from {$dbtbpre}enewsuser where `username`='$loginin'");
if(!$lur) exit('不存在的用户名'.$loginin);
$logininid=$lur['userid'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['groupid'];
$loginadminstyleid=$lur['adminstyleid'];
$incftp=0;
if($public_r['phpmode'])
{
include("../class/ftp.php");
$incftp=1;
}
require("../class/hinfofun.php");
$navtheid=(int)$_POST['filepass'];
AddNews($_POST,$logininid,$loginin);
db_close();
$empire=null;
/***生成目录的一个遍历算法***/
function maketree($ar,$id,$pre)
{
$ids='';
foreach($ar as $k=>$v){
$pid=$v['pid'];
$cname=$v['cname'];
$cid=$v['cid'];
if($pid==$id)
{
$ids.="<option value='$cid'>{$pre}{$cname}</option>";
foreach($ar as $kk=>$vv)
{
$pp=$vv['pid'];
if($pp==$cid)
{
$ids.=maketree($ar,$cid,$pre." ");
break;
}
}
}
}
return $ids;
}
?>
python的代码
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import time
from turtle import title
import urllib.request
import urllib.parse
import xlrd,openpyxl,random
def post(title, content):
query = "http://www.name.com/e/admin/fabu.php?pw=888"
data_form = {
"enews": "AddNews",
"classid": 1, # 栏目id
"bclassid": 0, # 父栏目id
"id": 0,
"filepass": int(time.time()), # 发布文章的时间戳
"username": "admin", # 后台用户名
"oldchecked": 1,
"ecmsnfrom": 1,
"ecmscheck": 0,
"havetmpic": 0,
"title": title,
"checked": 0,
"isgood": 0,
"firsttitle": 0,
"newstime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"writer": "admin",
"befrom": "",
"newstext": content,
"dokey": 1,
"copyimg": 1,
"autosize": 5000,
"istop": 0,
"newstempid": 0,
"groupid": 0,
"newspath":"2022/05", #栏目目录地址
"userfen": 0,
"onclick": 0,
"totaldown": 0,
"addnews": "提 交",
}
data = urllib.parse.urlencode(data_form).encode(encoding='utf-8')
req = urllib.request.Request(query, data=data)
res = urllib.request.urlopen(req, timeout=60)
result = res.read().decode('utf-8')
print(result)
if __name__ == "__main__":
wb = openpyxl.load_workbook('content.xlsx')
sheet = wb.active
#获取每一行的值
max_row=len(list(sheet.rows))
print("发布数量:", (max_row)-1)
for r in range(2,(max_row)+1): #第二行开始
title = sheet.cell(row=r, column=1).value
content = sheet.cell(row=r, column=2).value
print("开始发布:", title)
post(title,content)
这个代码是发布的的表格也就是xlsx,假如你是csv或者数据库,自己改下就行了。测试完美通过。感谢大佬
原文地址:https://www.4414.cn/thread-91716-1-1.html,网上找了很多,就这个是完整的。