Files
forust 7fb0a0e179 chore: batch lint fixes across userbot and edu_master
- S113: Add timeout=10 to all requests calls (74 fixes)
- E722: Replace bare except: with except Exception:
- B904: Replace redundant re-raise with bare raise
- E402: Add noqa for intentional late imports after import_library()
- S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage
- F601: Fix duplicate dict key in unsplash.py
- N802: Rename ReplyCheck -> reply_check with backward compat alias
- N813: Rename bs -> BS in icons.py
- B007/B020: Rename loop var _j in animations.py
- SIM102: Collapse nested if in autofwd.py
- SIM113: Use enumerate() in calculator.py
- A002: Add noqa for builtin shadowing in admlist.py
- F811: Add noqa for cohere redefinition
- edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes
- Add modules_list.txt with full module inventory
2026-06-19 15:36:25 +02:00

96 lines
3.5 KiB
Python

import requests
from pyrogram import Client, filters
from utils.misc import modules_help, prefix
from utils.scripts import format_exc, import_library
pcp = import_library('pubchempy')
INATURALIST_API_URL = 'https://api.inaturalist.org/v1/observations'
def get_marine_life_details(species_name):
params = {
'taxon_name': species_name,
'quality_grade': 'research',
'iconic_taxa': 'Mollusca,Fish,Crustacea',
'per_page': 1,
}
response = requests.get(INATURALIST_API_URL, params=params, timeout=10)
if response.status_code == 200:
data = response.json()
if data['total_results'] > 0:
observation = data['results'][0]
species = observation['taxon']['name']
common_name = observation['taxon']['preferred_common_name']
photo_url = observation['photos'][0]['url'] if observation['photos'] else 'No photo available'
description = observation.get('description', 'No description available.')
return {
'species': species,
'common_name': common_name,
'photo_url': photo_url,
'description': description,
}
else:
return {'error': 'No marine life found for this species.'}
else:
return {'error': f'Error {response.status_code}: Unable to connect to iNaturalist API.'}
@Client.on_message(filters.command('camistry', prefix) & filters.me)
async def fetch_chemical_data_with_visual(_, message):
query = ' '.join(message.text.split()[1:]) # Combine query words properly
try:
# Fetch chemical data by name
results = pcp.get_compounds(query, 'name', record_type='3d')
if results:
compound = results[0]
# Send chemical information without SMILES structure
info = (
f'<b>Chemical Data for {compound.iupac_name}</b>\n\n'
f'<b>Molecular Formula:</b> <code>{compound.molecular_formula}</code>\n'
f'<b>Molecular Weight:</b> <code>{compound.molecular_weight}</code>\n'
f'<b>CID:</b> <code>{compound.cid}</code>\n'
f'<b>Synonyms:</b> <code>{", ".join(compound.synonyms[:5])}</code>\n'
)
await message.edit_text(info)
else:
await message.edit_text(f"No chemical data found for the query: '{query}'")
except pcp.PubChemHTTPError as http_err:
await message.edit_text(f'HTTP error occurred: {format_exc(http_err)}')
except Exception as e:
await message.edit_text(f'An error occurred: {format_exc(e)}')
@Client.on_message(filters.command('marinelife', prefix) & filters.me)
async def marine_life_command(_, message):
if len(message.command) < 2:
await message.edit_text(f'Please specify a species name. Example: {prefix}marinelife dolphin')
return
species_name = ' '.join(message.command[1:])
marine_life = get_marine_life_details(species_name)
if 'error' in marine_life:
await message.edit_text(marine_life['error'])
else:
reply_text = (
f'<b>Species</b>: <code>{marine_life["species"]}</code>\n'
f'<b>Common Name</b>: <code>{marine_life["common_name"]}</code>\n'
f'<b>Description</b>: <code>{marine_life["description"]}</code>\n'
f"<a href='{marine_life['photo_url']}'>Photo</a>"
)
await message.edit_text(reply_text)
modules_help['cama'] = {
'camistry [text]': ' getting camicale info',
'marinelife [text]': ' getting marinelife info',
}