mirror of
https://github.com/Nick80835/microbot
synced 2025-08-29 13:38:55 +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|)")
|
||||
async def fourchan(event):
|
||||
if event.pattern_match.group(1):
|
||||
as_file = True
|
||||
else:
|
||||
as_file = False
|
||||
as_file = bool(event.pattern_match.group(1))
|
||||
|
||||
session = ClientSession()
|
||||
|
||||
|
@ -31,22 +31,21 @@ async def danbooru(event):
|
||||
async with session.get(DAN_URL, params=params) as response:
|
||||
if response.status == 200:
|
||||
response = await response.json()
|
||||
await session.close()
|
||||
else:
|
||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||
await session.close()
|
||||
return
|
||||
|
||||
await session.close()
|
||||
|
||||
if not response:
|
||||
await event.reply(f"`No results for query: `**{event.args}**")
|
||||
return
|
||||
|
||||
valid_urls = []
|
||||
|
||||
for url in ['file_url', 'large_file_url', 'source']:
|
||||
if url in response[0].keys():
|
||||
valid_urls.append(response[0][url])
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
|
||||
if not valid_urls:
|
||||
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:
|
||||
if response.status == 200:
|
||||
response = (await response.json())[0]
|
||||
response = await response.json()
|
||||
await session.close()
|
||||
else:
|
||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||
await session.close()
|
||||
return
|
||||
|
||||
await session.close()
|
||||
|
||||
if not response:
|
||||
await event.reply(f"`No results for query: `**{event.args}**")
|
||||
return
|
||||
|
||||
valid_urls = []
|
||||
|
||||
for url in ['file_url', 'large_file_url', 'source']:
|
||||
if url in response.keys():
|
||||
valid_urls.append(response[url])
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
|
||||
if not valid_urls:
|
||||
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:
|
||||
if response.status == 200:
|
||||
response = await response.json()
|
||||
await session.close()
|
||||
else:
|
||||
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
||||
await session.close()
|
||||
return
|
||||
|
||||
await session.close()
|
||||
|
||||
if not response:
|
||||
await event.reply(f"`No results for query: `**{event.args}**")
|
||||
return
|
||||
|
||||
valid_urls = []
|
||||
|
||||
for item in response:
|
||||
if 'file_url' in item.keys():
|
||||
valid_urls.append(item['file_url'])
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
|
||||
if not valid_urls:
|
||||
await event.reply(f"`Failed to find URLs for query: `**{event.args}**")
|
||||
|
Loading…
x
Reference in New Issue
Block a user