mirror of
https://github.com/Nick80835/microbot
synced 2025-08-30 14:08:31 +00:00
clean up scrapers a bit
This commit is contained in:
parent
09f585d69f
commit
b5ce768917
@ -16,10 +16,7 @@ VALID_ENDS = (".mp4", ".jpg", ".jpeg", ".png", ".gif")
|
|||||||
|
|
||||||
@ldr.add("4c(f|)")
|
@ldr.add("4c(f|)")
|
||||||
async def fourchan(event):
|
async def fourchan(event):
|
||||||
if event.pattern_match.group(1):
|
as_file = bool(event.pattern_match.group(1))
|
||||||
as_file = True
|
|
||||||
else:
|
|
||||||
as_file = False
|
|
||||||
|
|
||||||
session = ClientSession()
|
session = ClientSession()
|
||||||
|
|
||||||
|
@ -31,22 +31,21 @@ async def danbooru(event):
|
|||||||
async with session.get(DAN_URL, params=params) as response:
|
async with session.get(DAN_URL, params=params) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
response = await response.json()
|
response = await response.json()
|
||||||
|
await session.close()
|
||||||
else:
|
else:
|
||||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||||
await session.close()
|
await session.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
await session.close()
|
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
await event.reply(f"`No results for query: `**{event.args}**")
|
await event.reply(f"`No results for query: `**{event.args}**")
|
||||||
return
|
return
|
||||||
|
|
||||||
valid_urls = []
|
valid_urls = []
|
||||||
|
|
||||||
for url in ['file_url', 'large_file_url', 'source']:
|
for post in response:
|
||||||
if url in response[0].keys():
|
if 'file_url' in post.keys():
|
||||||
valid_urls.append(response[0][url])
|
valid_urls.append(post['file_url'])
|
||||||
|
|
||||||
if not valid_urls:
|
if not valid_urls:
|
||||||
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
||||||
|
@ -34,23 +34,22 @@ async def gelbooru(event):
|
|||||||
|
|
||||||
async with session.get(GEL_URL, params=params) as response:
|
async with session.get(GEL_URL, params=params) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
response = (await response.json())[0]
|
response = await response.json()
|
||||||
|
await session.close()
|
||||||
else:
|
else:
|
||||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||||
await session.close()
|
await session.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
await session.close()
|
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
await event.reply(f"`No results for query: `**{event.args}**")
|
await event.reply(f"`No results for query: `**{event.args}**")
|
||||||
return
|
return
|
||||||
|
|
||||||
valid_urls = []
|
valid_urls = []
|
||||||
|
|
||||||
for url in ['file_url', 'large_file_url', 'source']:
|
for post in response:
|
||||||
if url in response.keys():
|
if 'file_url' in post.keys():
|
||||||
valid_urls.append(response[url])
|
valid_urls.append(post['file_url'])
|
||||||
|
|
||||||
if not valid_urls:
|
if not valid_urls:
|
||||||
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
||||||
|
@ -31,22 +31,21 @@ async def sankaku(event):
|
|||||||
async with session.get(SAN_URL, params=params) as response:
|
async with session.get(SAN_URL, params=params) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
response = await response.json()
|
response = await response.json()
|
||||||
|
await session.close()
|
||||||
else:
|
else:
|
||||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||||
await session.close()
|
await session.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
await session.close()
|
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
await event.reply(f"`No results for query: `**{event.args}**")
|
await event.reply(f"`No results for query: `**{event.args}**")
|
||||||
return
|
return
|
||||||
|
|
||||||
valid_urls = []
|
valid_urls = []
|
||||||
|
|
||||||
for item in response:
|
for post in response:
|
||||||
if 'file_url' in item.keys():
|
if 'file_url' in post.keys():
|
||||||
valid_urls.append(item['file_url'])
|
valid_urls.append(post['file_url'])
|
||||||
|
|
||||||
if not valid_urls:
|
if not valid_urls:
|
||||||
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user