stahI

Untitled

May 3rd, 2021
519
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import argparse
  3. import os
  4. import mechanize
  5. import json
  6. from bs4 import BeautifulSoup
  7. import requests
  8. import configparser
  9.  
  10. parser = argparse.ArgumentParser()
  11. parser.add_argument('-c', '--config', type=str, help="specify configfile", required=True)
  12. args = parser.parse_args()
  13. configpath = args.config
  14.  
  15. config = configparser.ConfigParser()
  16. config.read(configpath)
  17.  
  18. def telegram_bot_sendtext(bot_message):
  19.     bot_token = 'MEINE_BOT_ID'
  20.     bot_chatID = config.get("telegram","chatID")
  21.     send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
  22.  
  23.     response = requests.get(send_text)
  24.  
  25.     return response.json()
  26.  
  27. br = mechanize.Browser()
  28. br.set_handle_robots(False)
  29. br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
  30.  
  31. sign_in = br.open("https://almaweb.uni-leipzig.de/")
  32. br.select_form(name = "cn_loginForm")
  33. br["usrname"] = config.get("almaweb","username")
  34. br["pass"] = config.get("almaweb","password")
  35. logged_in = br.submit()
  36. logincheck = logged_in.read()
  37. results = {}
  38. notenpath = config.get("almaweb","notenpath")
  39. if os.path.exists(notenpath):
  40.     results = json.load(open(notenpath))
  41. for link in br.links(url_regex="EXAMRESULTS"):
  42.     req = br.follow_link(link).read()
  43.     soup = BeautifulSoup(req, features="html5lib")
  44.     rows = soup.findAll("tr",{"class": "tbdata"})
  45.     for row in rows:
  46.         aux = row.findAll('td')
  47.         if (' '.join(aux[0].get_text(strip=True, separator=" ").split()) not in results):
  48.             key = ' '.join(aux[0].get_text(strip=True, separator=" ").split())
  49.             value = ' '.join(aux[2].get_text(strip=True, separator=" ").split())
  50.             results[key] = value
  51.             json.dump(results, open(notenpath, 'w'))
  52.             telegram_bot_sendtext("Fach:" + key + "\nNote: " + value)
  53.  
  54.  
  55.  
  56.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×