Skip to content

Instantly share code, notes, and snippets.

@justheuristic
Last active December 23, 2020 19:17
Show Gist options
  • Save justheuristic/eaf1cf4858e6956702134d039e30f9d7 to your computer and use it in GitHub Desktop.
Save justheuristic/eaf1cf4858e6956702134d039e30f9d7 to your computer and use it in GitHub Desktop.
import time
from math import isfinite
import pandas as pd
import selenium.webdriver
data = pd.read_csv('avtomaticheskaia-obrabotka-tekstov-2020-autumn - avtomaticheskaia-obrabotka-tekstov-2020-autumn.csv')
# ^-- file format: https://docs.google.com/spreadsheets/d/1GcdT7eID_wNMjjxV0v6T0kOBRHn6Bg79qO80vFY_zgg/edit#gid=781547499
assignment_title = 'Week9 - Word alignment'
wait_after_approved = 1
br = selenium.webdriver.Firefox()
br.get('https://lk.yandexdataschool.ru/courses/2020-autumn/7.838-avtomaticheskaia-obrabotka-tekstov/')
# enter your data here. Do not forget to remove it before sharing this code :)
br.find_element_by_css_selector('#id_username').send_keys('[email protected]')
br.find_element_by_css_selector('#id_password').send_keys('YOURPASSWORD')
br.find_element_by_css_selector('.sign-up-in').click()
#find assignment index and student grade ids
br.get('https://lk.yandexdataschool.ru/teaching/marks/')
grade_ids = [
grade_id_elem.find_element_by_tag_name('select').get_property('name')
for grade_id_elem in br.find_element_by_css_selector('.grid').find_elements_by_css_selector('.__final_grade')
]
assignment_elems = br.find_element_by_css_selector('.headers').find_elements_by_tag_name('div')
assignment_nchild_in_vedomost = [div.text for div in assignment_elems].index(assignment_title)
for _, row in data.iterrows():
if not isfinite(row[assignment_title]):
print(f"Student {row['Фамилия']} {row['Имя'].strip()[0]}. {assignment_title} = skipped")
continue
# select submission
br.get('https://lk.yandexdataschool.ru/teaching/marks/')
student_index_in_table = grade_ids.index(f"final_grade_{row['id']}")
br.find_element_by_css_selector(
f'div.student:nth-child({student_index_in_table + 1}) > div:nth-child({assignment_nchild_in_vedomost + 1}) > a:nth-child(1)'
).click()
# verify that we've chosen the right submission
submission_title_string = br.find_element_by_css_selector('.h2-and-buttons').text
for item in row['Имя'], row['Фамилия'], assignment_title:
assert item in submission_title_string
br.find_element_by_css_selector('#id_score').clear()
br.find_element_by_css_selector('#id_score').send_keys(str(row[assignment_title]))
br.find_element_by_css_selector('button.btn').click()
time.sleep(wait_after_approved)
print(f"Student {row['Фамилия']} {row['Имя'].strip()[0]}. - {assignment_title} = {row[assignment_title]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment