Skip to content

Instantly share code, notes, and snippets.

@alirezaahani
Created April 23, 2021 11:47
Show Gist options
  • Save alirezaahani/99f96df9eeb06e702eccd39b45e50f31 to your computer and use it in GitHub Desktop.
Save alirezaahani/99f96df9eeb06e702eccd39b45e50f31 to your computer and use it in GitHub Desktop.
incompelete tasks courses.aut.ac.ir
import requests
from bs4 import BeautifulSoup as bs
from time import sleep
from math import ceil
username = input("Username:")
password = input("Password:")
with requests.session() as session:
res = session.get("https://courses.aut.ac.ir/login/")
soup = bs(res.text, "html.parser")
token = soup.find("input", {"name":"logintoken"})["value"]
login_data = {
"password":password,
"username":username,
"anchor":"",
"logintoken":token,
"rememberusername":"1"
}
session.post("https://courses.aut.ac.ir/login/index.php",login_data)
res = session.get("https://courses.aut.ac.ir/my")
if res.ok and res.url == "https://courses.aut.ac.ir/my":
print("Logged in successfully")
else:
print(f"""Could not login into the site.
Reason: {res.reason}
Status code: {res.status_code}
Object: {res}
Url: {res.url}
Username: {username}
Password: {password}
Token: {token}""")
exit()
soup = bs(res.text, "html.parser")
session_key = soup.find("a", {"class":"dropdown-item menu-action", "data-title":"logout,moodle"})['href']
print(f"Session key: {session_key.split('?sesskey=')[1]}")
course_links = {}
for course in soup.findAll("div",{"class":"column c1"}):
for link in course.findAll('a'):
course_links[link.text] = link['href']
sleep(2)
completion_states = {}
checked = 0
with open('incompelte_dump.txt','w') as f:
for name,link in course_links.items():
res = session.get(link)
if 'کامل نشده است؛ انتخاب کنید تا به عنوان کامل شده علامت بخورد' in res.text:
print(f"Incomplete task :{name}")
f.write(f'{name}\n')
checked += 1
print(f'Progress: {ceil(( checked / len(course_links.items()) ) * 100)}%')
sleep(2)
print("Done! Logging out.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment