更新规则

This commit is contained in:
qcminecraft 2021-02-04 08:22:39 +08:00
parent 988d884e8c
commit eac23a7510
5 changed files with 20 additions and 9 deletions

Binary file not shown.

View File

@ -3,12 +3,14 @@
"name": "misskey.io", "name": "misskey.io",
"url" : "https://misskey.io", "url" : "https://misskey.io",
"token": "9v1t2poJeEh5RI74VqBCzJLHk9N6Weds", "token": "9v1t2poJeEh5RI74VqBCzJLHk9N6Weds",
"visibility": "specified",
"channel": "8hrcz5rdvp" "channel": "8hrcz5rdvp"
}, },
"misskey.dev": { "misskey.dev": {
"name": "misskey.dev", "name": "misskey.dev",
"url" : "https://misskey.dev", "url" : "https://misskey.dev",
"token": "qnZl1OmgnAlTRbRO", "token": "qnZl1OmgnAlTRbRO",
"visibility": "public",
"channel": false "channel": false
} }
} }

View File

@ -9,15 +9,11 @@ class Misskey:
config = {} config = {}
debug = True debug = True
def post(self, baseurl, content, channel=""): def post(self, baseurl, content, channel="", visibility="public"):
print("Creating new post to", baseurl, ":", content) print("Creating new post to", baseurl, ":", content)
req_url = baseurl + "/api/notes/create" req_url = baseurl + "/api/notes/create"
if self.debug:
visb = "specified"
else:
visb = "public"
body = { body = {
"visibility": visb, "visibility": visibility,
"text": content, "text": content,
"localOnly": channel != "", "localOnly": channel != "",
"i": self.config['token'] "i": self.config['token']

View File

@ -1,6 +1,10 @@
{ {
"DWNews":{ "DWNews":{
"rss_source": "https://rsshub.app/dwnews/yaowen/global", "rss_source": "https://rsshub.app/dwnews/yaowen/global",
"identify": "misskey.io" "identity": "misskey.io"
},
"NHK": {
"rss_source": "https://rsshub.app/nhk/news_web_easy",
"identity": "misskey.io"
} }
} }

View File

@ -37,6 +37,13 @@ def spider(rule_name, rss_url):
result = xmltodict.parse(fetch.content) result = xmltodict.parse(fetch.content)
c.execute('INSERT INTO "main"."spider_log" ("rule_name", "rss_url", "result_json", "timestamp") ' c.execute('INSERT INTO "main"."spider_log" ("rule_name", "rss_url", "result_json", "timestamp") '
'VALUES (?, ?, ?, ?)', (rule_name, rss_url, json.dumps(result), time.time())) 'VALUES (?, ?, ?, ?)', (rule_name, rss_url, json.dumps(result), time.time()))
item_list = result['rss']['channel']['item']
for i in item_list:
print("Got: ", i['title'])
desc = i['description'].replace("<blockquote>", "").replace("</blockquote>", "")
c.execute('INSERT INTO "main"."result" ("rule_name", "url", "title", "description", "timestamp")'
' VALUES (?, ?, ?, ?, ?)', (rule_name, i['link'], i['title'], desc, time.time()))
c.close() c.close()
end = time.time() end = time.time()
print("Fetch done in", end - start, "s") print("Fetch done in", end - start, "s")
@ -49,14 +56,16 @@ def fetch_detail(url):
if __name__ == '__main__': if __name__ == '__main__':
print("Misskey X61 RSS Bot initialized") print("Misskey X61 RSS Bot initialized")
spider("DuoWei", "https://rsshub.app/dwnews/yaowen/global")
config = json_read("config.json") config = json_read("config.json")
rules = json_read("rules.json") rules = json_read("rules.json")
for key in rules:
spider(key, rules[key]['rss_source'])
Misskey.config = config['misskey.io'] Misskey.config = config['misskey.io']
req = Misskey.post(baseurl="https://misskey.io", content="Beep.. Beep Beep! Beep:" + str(time.time()), self=Misskey) # req = Misskey.post(baseurl="https://misskey.io", content="Beep.. Beep Beep! Beep:" + str(time.time()), self=Misskey)
conn.commit() conn.commit()
conn.close() conn.close()