Created
April 13, 2020 22:05
-
-
Save jqqqqqqqqqq/75b52e9ad6cae112d5df98364c8a4590 to your computer and use it in GitHub Desktop.
telegram @whatismyoptstatusbot opt status lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiogram import Bot, Dispatcher, types | |
from aiohttp import ClientSession | |
from bs4 import BeautifulSoup | |
import asyncio | |
import re | |
async def get_status(receipt_number): | |
url = 'https://egov.uscis.gov/casestatus/mycasestatus.do' | |
# changeLocale=&appReceiptNum=YSC1790007419&initCaseSearch=CHECK+STATUS | |
values = {'changeLocale': '', | |
'appReceiptNum': receipt_number, | |
'initCaseSearch': 'CHECK STATUS'} | |
async with ClientSession() as session: | |
result = await session.post(url, data=values) | |
text = await result.text() | |
soup = BeautifulSoup(text, 'html.parser') | |
statusTag = soup.find('div', {'class': 'current-status-sec'}) | |
contents = statusTag.text.split("\n") | |
content = contents[2].strip() | |
print(content) | |
return content | |
loop = asyncio.get_event_loop() | |
bot = Bot('TOKEN', loop=loop) | |
dp = Dispatcher(bot, loop=loop) | |
matcher = re.compile(r'^[a-zA-Z]{3}[0-9]{10}$') | |
@dp.message_handler(commands='q') | |
async def handle_query(message: types.Message): | |
args = message.get_args() | |
if not matcher.match(args): | |
text = 'Usage: /q + your case number' | |
await message.reply(text) | |
return | |
result = await get_status(args) | |
await message.reply(result) | |
@dp.message_handler(commands='start') | |
async def handle_start(message: types.Message): | |
text = f'Hello {message.from_user.full_name}! This is a bot that can read ' \ | |
f'"egov.uscis.gov" and look up your OPT status. Type /q + your case number to start.' | |
await message.reply(text) | |
loop.create_task(dp.start_polling()) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment