aheskandani commited on
Commit
1935825
1 Parent(s): 572dccb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -21,14 +21,27 @@ def start(update: Update, context: CallbackContext):
21
  def send_captcha(update: Update, context: CallbackContext):
22
  ''' Entry point of conversation this gives buttons to user'''
23
  chat_id = update.effective_chat.id
24
- url = 'https://pooya.um.ac.ir/gateway/SecurityImage/ShowSecurityImage.php?rand=797377160&rand2=UVJ3Rko2SXlDbGtoRC9oNnNVVXVhOFcxdTNxVEhqVDhBZHBvVXRrWFZuaz0='
 
25
  urllib.request.urlretrieve(url, 'captcha.png')
 
26
  context.bot.send_photo(chat_id, photo=open('captcha.png', 'rb'))
27
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  if __name__ == '__main__':
29
  updater = Updater(token=bot_token)
30
  updater.dispatcher.add_handler(CommandHandler('start', start))
31
  updater.dispatcher.add_handler(CommandHandler('img', send_captcha))
32
  updater.start_polling()
33
- print('Bot started ..........')
34
- چچ
 
21
  def send_captcha(update: Update, context: CallbackContext):
22
  ''' Entry point of conversation this gives buttons to user'''
23
  chat_id = update.effective_chat.id
24
+ url = captcha_url()
25
+ context.bot.send_message(chat_id, text=url)
26
  urllib.request.urlretrieve(url, 'captcha.png')
27
+ context.bot.send_message(chat_id, text='Downloaded')
28
  context.bot.send_photo(chat_id, photo=open('captcha.png', 'rb'))
29
 
30
+ def captcha_url():
31
+ web_url = 'https://pooya.um.ac.ir/gateway/PuyaAuthenticate.php'
32
+ req_url = 'https://pooya.um.ac.ir/gateway/UserInterim.php'
33
+ headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}
34
+ session = requests.session()
35
+ resp = session.get(web_url, headers=headers)
36
+ soup = BeautifulSoup(resp.content, 'html.parser')
37
+ img_src = soup.find('img', id='secimg')['src']
38
+ filename = 'C:/Users/Home/OneDrive/Desktop/captcha.png'
39
+ capcha_src = 'https://pooya.um.ac.ir' + img_src[2:]
40
+ return capcha_src
41
+
42
  if __name__ == '__main__':
43
  updater = Updater(token=bot_token)
44
  updater.dispatcher.add_handler(CommandHandler('start', start))
45
  updater.dispatcher.add_handler(CommandHandler('img', send_captcha))
46
  updater.start_polling()
47
+ print('Bot started ..........')