feat: init
This commit is contained in:
27
Rss.py
Normal file
27
Rss.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import feedparser
|
||||||
|
import pprint
|
||||||
|
import re
|
||||||
|
|
||||||
|
class Rss():
|
||||||
|
def __init__(self, id, url, rss_pipe_handler, result_handler) -> None:
|
||||||
|
self.rss_url = url
|
||||||
|
self.id = id
|
||||||
|
self.rss_pipe_handler = rss_pipe_handler
|
||||||
|
self.result_handler = result_handler
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
rss_source = feedparser.parse(self.rss_url)
|
||||||
|
result_list = self.rss_pipe_handler(rss_source['entries'])
|
||||||
|
|
||||||
|
result_list = self.compare_result(pprint.pprint(result_list))
|
||||||
|
ids = self.result_handler(result_list)
|
||||||
|
|
||||||
|
self.save_result(ids)
|
||||||
|
return
|
||||||
|
|
||||||
|
def compare_result(self, list):
|
||||||
|
return list
|
||||||
|
|
||||||
|
def save_result(self, ids):
|
||||||
|
return ids
|
||||||
|
|
18
RssManager.py
Normal file
18
RssManager.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import thread
|
||||||
|
|
||||||
|
from Rss import *
|
||||||
|
|
||||||
|
class RssManager():
|
||||||
|
def __init__(self, rss_options):
|
||||||
|
self.rss_list = [Rss(opt['id'], opt['url'], opt['rss_pipe_handler'], opt['result_handler']) for opt in rss_options]
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
for rss in rss_list:
|
||||||
|
thread.start_new_thread(rss.run)
|
||||||
|
except:
|
||||||
|
print('Error: unable to start thread')
|
||||||
|
print('Info: start sync run')
|
||||||
|
for rss in rss_list:
|
||||||
|
rss.run()
|
||||||
|
|
20
handlers/PixivHandler.py
Normal file
20
handlers/PixivHandler.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
def pixiv_handler(entries):
|
||||||
|
# 整理为JSON数组
|
||||||
|
pixiv_list = []
|
||||||
|
for entry in entries:
|
||||||
|
links = []
|
||||||
|
for i in entry['content']:
|
||||||
|
pattern = re.compile(
|
||||||
|
r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
|
||||||
|
links = (re.findall(pattern, i['value']))
|
||||||
|
|
||||||
|
tag_pattern = re.compile(r'tags/(.*)/')
|
||||||
|
item = {id: entry['id'], 'title': entry['title'], 'link': links,
|
||||||
|
'author': entry['author'], 'tag': re.findall(tag_pattern, entry['source'].id)}
|
||||||
|
|
||||||
|
pixiv_list.append(item)
|
||||||
|
|
||||||
|
return pixiv_list
|
||||||
|
|
||||||
|
def pixiv_result_handler(list):
|
||||||
|
pass
|
0
handlers/__init__.py
Normal file
0
handlers/__init__.py
Normal file
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
thread
|
||||||
|
feedparser
|
||||||
|
pprint
|
||||||
|
requests
|
||||||
|
webdavclient3
|
20
start.py
Normal file
20
start.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from RssManager import *
|
||||||
|
from handlers.PixivHandler import *
|
||||||
|
|
||||||
|
class CreateRssServer():
|
||||||
|
def __init__(self):
|
||||||
|
rss_options = [
|
||||||
|
{
|
||||||
|
'id': 'pixiv',
|
||||||
|
'url': 'https://rss.hiiragi.club:8081/public.php?op=rss&id=-2&is_cat=0&q=&key=pp9ejw64463b6621a0b',
|
||||||
|
'rss_pipe_handler': pixiv_handler,
|
||||||
|
'result_handler': pixiv_result_handler
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self.app = RssManager(rss_options)
|
||||||
|
|
||||||
|
rss_server = CreateRssServer()
|
||||||
|
app = rss_server.app
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run()
|
Reference in New Issue
Block a user