Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import json
- from pprint import pprint
- import sys
- import time
- import datetime
- s = requests.session()
- def login():
- url = "http://informatics.mccme.ru/login/index.php"
- data = dict(
- username = "",
- password = ""
- )
- s.post(url, data)
- def get_table(url):
- result = s.get(url).text
- return json.loads(result)["result"]["text"]
- urls = [
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10529&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10599&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10639&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10718&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10779&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10817&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- "http://informatics.mccme.ru/moodle/ajax/ajax.php?problem_id=0&group_id=5100&user_id=0&lang_id=-1&status_id=-1&statement_id=10843&objectName=submits&count=10000&with_comment=&page=0&action=getHTMLTable",
- ]
- students = dict()
- for url in urls:
- soup = BeautifulSoup(get_table(url), 'html.parser')
- trs = list(soup.find_all("tr"))[1:]
- for tr in trs:
- #print tr
- student = tr.find_all("td")[1].find("a").text
- if not (student in students):
- students[student] = dict()
- lang = tr.find_all("td")[4].text
- status = tr.find_all("td")[5].text.strip()
- score = tr.find_all("td")[7].text.strip()
- problem = unicode(tr.find_all("td")[2].find("a").text).encode("utf8")
- try:
- score = int(score)
- except:
- score = 0
- # print student, status, problem, lang
- if "OK" in status and ("Java" in lang or not lang):
- # print "yeee"
- if problem in students[student].keys():
- students[student][problem] = max(students[student][problem],score)
- else:
- students[student][problem] = score
- result = []
- for student in students.keys():
- sum = 0
- plist = []
- for problem in students[student].keys():
- plist.append((problem, students[student][problem]))
- sum += students[student][problem]
- item = (student,plist,sum)
- result.append(item)
- result.sort(key=lambda item: item[2])
- result.reverse()
- header = """
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- """
- footer = """
- </body>
- </html>
- """
- while True:
- with open("results.html","w") as f:
- sum = 0
- f.write(header)
- for item in result:
- f.write("%s %s %s<br>" % (item[0].encode('utf8'), item[2], len(item[1])))
- sum += len(item[1])
- for problem in item[1]:
- f.write("%s %s<br>" % (problem[0],problem[1]))
- f.write("<br>")
- #print sum
- f.write(footer)
- print "Last update at:%s\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
- time.sleep(60*30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement