def run(bot, sess):
subs = sess.query(SiteSub).all()
for sub in subs: # type: SiteSub
async with aiohttp.ClientSession() as session:
try:
async with session.get(sub.url) as res:
new_body: str = await res.text()
if sub.body != new_body:
old_body_lines = sub.body.splitlines(keepends=True)
new_body_lines = new_body.splitlines(keepends=True)
d = Differ()
diff = [
SPACE_RE.sub(' ', x).rstrip() for x in d.compare(
old_body_lines,
new_body_lines
)
if x[0] not in [' ', '?']
]
await bot.say(
sub.user,
'`{}` ?? ??? ?????!\n```\n{}\n```'.format(
sub.url,
'\n'.join(diff),
)
)
sub.body = new_body
with sess.begin():
sess.add(sub)
except aiohttp.client_exceptions.ClientConnectorError:
await bot.say(
sub.user,
f'`{sub.url}` ? ??? ? ???!'
)
评论列表
文章目录