Python YES!
This commit is contained in:
parent
d6cdb00c1b
commit
e6251155da
|
@ -0,0 +1,2 @@
|
|||
config.json
|
||||
.idea/
|
|
@ -0,0 +1,10 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 数据源本地存储已忽略文件
|
||||
/../../../../:\Workspace\x61bot\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
|
||||
*
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="DB" uuid="ac3a5d78-6091-49a0-aea9-ea5fe008b39a">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:C:\Workspace\x61bot\DB.sqlite3</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.34.0/sqlite-jdbc-3.34.0.jar</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/x61bot.iml" filepath="$PROJECT_DIR$/.idea/x61bot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"misskey.io": {
|
||||
"name": "misskey.io",
|
||||
"url" : "https://misskey.io",
|
||||
"token": "9v1t2poJeEh5RI74VqBCzJLHk9N6Weds",
|
||||
"channel": "8hrcz5rdvp"
|
||||
},
|
||||
"misskey.dev": {
|
||||
"name": "misskey.dev",
|
||||
"url" : "https://misskey.dev",
|
||||
"token": "qnZl1OmgnAlTRbRO",
|
||||
"channel": false
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
require ("lib.php");
|
||||
|
||||
|
||||
echo xmlToJSON(sendReq("https://rsshub.app/dwnews/yaowen/global"));
|
61
lib.php
61
lib.php
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* CURL实现GET或POST请求
|
||||
* @param $url 请求地址
|
||||
* @param $mode 请求方式(GET/POST)
|
||||
* @param $data 请求参数,执行POST请求时需要
|
||||
* @return object 返回对象数据包
|
||||
*/
|
||||
function sendReq($url, $data = array(), $mode = 'GET'){
|
||||
// 初始化
|
||||
$curl = curl_init();
|
||||
// 访问的URL
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
// 只获取页面内容,但不输出
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
// 验证是否是https请求
|
||||
if(substr($url, 0, 5) == 'https'){
|
||||
// https请求,不验证证书
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
// https请求,不验证HOST
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
if($mode == 'POST'){
|
||||
// 设置请求方式为POST请求
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
// POST请求数据
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
// 执行CURL请求
|
||||
$result = curl_exec($curl);
|
||||
// 关闭curl,释放资源
|
||||
curl_close($curl);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间戳,精确到毫秒
|
||||
* @return float
|
||||
*/
|
||||
function microtime_float()
|
||||
{
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return ((float)$usec + (float)$sec);
|
||||
}
|
||||
|
||||
function xmlToJSON($content){
|
||||
$dir_name = "cache/".date("Y-m-d");
|
||||
$cache_name = $dir_name."/".microtime_float();
|
||||
|
||||
if(!is_dir($dir_name)){
|
||||
mkdir($dir_name);
|
||||
}
|
||||
|
||||
$xml = $content;
|
||||
|
||||
file_put_contents("$cache_name".".xml", $xml);
|
||||
|
||||
$json = json_encode(simplexml_load_file($cache_name.".xml"));
|
||||
file_put_contents("$cache_name".".json", $json);
|
||||
return $json;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
# Misskey API Docs: https://misskey.io/api-doc
|
||||
import json
|
||||
import sqlite3
|
||||
import requests
|
||||
import xmltodict
|
||||
import time
|
||||
|
||||
config_file = open('config.json', 'r')
|
||||
config = json.loads(config_file.read())
|
||||
config_file.close()
|
||||
conn = sqlite3.connect('DB.sqlite3')
|
||||
print("Opened database successfully")
|
||||
|
||||
|
||||
def xml_to_json(xml):
|
||||
pars = xmltodict.parse(xml)
|
||||
return json.dumps(pars)
|
||||
|
||||
|
||||
def spider(rule_name, rss_url):
|
||||
print("Fetch: ", rss_url)
|
||||
c = conn.cursor()
|
||||
result = xmltodict.parse(requests.get(rss_url).content)
|
||||
c.execute('INSERT INTO "main"."spider_log" ("rule_name", "rss_url", "result_json", "timestamp") '
|
||||
'VALUES (?, ?, ?, ?)', (rule_name, rss_url, json.dumps(result), time.time()))
|
||||
c.close()
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Misskey X61 RSS Bot")
|
||||
spider("duowei", "https://rsshub.app/dwnews/yaowen/global")
|
||||
conn.commit()
|
||||
conn.close()
|
Loading…
Reference in New Issue