Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Last active January 12, 2020 15:35
Show Gist options
  • Save DustinAlandzes/9e0884f1003d82dcef82dac152d068d1 to your computer and use it in GitHub Desktop.
Save DustinAlandzes/9e0884f1003d82dcef82dac152d068d1 to your computer and use it in GitHub Desktop.
Script to pull assignments that need to be graded from bootcamp spot (now excluding Milestone and Juan)
import random
from github import Github
from main import BootcampSpot
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN")
g = Github(ACCESS_TOKEN)
bootcamp_spot = BootcampSpot()
repo = g.get_repo("DustinAlandzes/Full-Stack-Web-Development-Anki-Deck")
open_issues = list(repo.get_issues(state='open'))
closed_issues = list(repo.get_issues(state='closed'))
issues = [issue.title for issue in open_issues]
issues.extend([issue.title for issue in closed_issues])
assignments = bootcamp_spot.get_assignments()
for assignment in assignments:
note_txt = f"{assignment.get('studentName')} - {assignment.get('assignmentTitle')}"
not_added_already = note_txt not in issues
is_submitted = assignment.get('submitted')
not_graded = not assignment.get('grade')
not_a_milestone = not 'Milestone' in assignment.get('assignmentTitle')
if all([not_added_already, is_submitted, not_graded, not_a_milestone]):
# choose randomly between Dustin and David
assign_to = random.choice(['DustinAlandzes', None])
if assign_to:
repo.create_issue(title=note_txt, assignee=assign_to)
else:
repo.create_issue(title=note_txt)
issues.append(note_txt)
import os
import random
import requests
BASE_URL = "https://bootcampspot.com/api/instructor/v1/"
COURSE_ID = 2163
EMAIL = os.environ.get('EMAIL')
PASSWORD = os.environ.get('PASSWORD')
class BootcampSpot:
def __init__(self):
self.auth_token = None
self.login()
def login(self) -> None:
endpoint = "login"
response = requests.post(BASE_URL + endpoint, json={'email': EMAIL, 'password': PASSWORD})
response.raise_for_status()
self.auth_token = response.json().get("authenticationInfo", {}).get("authToken", "")
def get_assignments(self):
endpoint = "grades"
response = requests.post(BASE_URL + endpoint, json={'courseId': COURSE_ID},
headers={'authToken': self.auth_token, 'Content-Type': 'application/json'})
response.raise_for_status()
return response.json()
def generate_two_lists_of_ungraded_assignments(self):
assignments = self.get_assignments()
assignments_todo = [assignment for assignment in assignments if
assignment.get('submitted') and not assignment.get('grade')
and 'Milestone' not in assignment.get('assignmentTitle')
and 'Juan Acosta' not in assignment.get('studentName')]
# shuffle, return two lists, from 0 to n_assignments/2 and from n_assignements/2 to the end
random.shuffle(assignments_todo)
n_assignments = len(assignments_todo)
return assignments_todo[:n_assignments // 2], assignments_todo[n_assignments // 2:]
if __name__ == "__main__":
bootcampspot = BootcampSpot()
a, b = bootcampspot.generate_two_lists_of_ungraded_assignments()
print("Dustin: ")
for assignment in a:
print(assignment.get('assignmentTitle'), assignment.get('studentName'))
print("David: ")
for assignment in b:
print(assignment.get('assignmentTitle'), assignment.get('studentName'))
from unittest import TestCase
from main import BootcampSpot
class TestBootcampSpot(TestCase):
def setUp(self) -> None:
self.client = BootcampSpot()
def test_login(self):
self.client.login()
self.assertEqual(type(self.client.auth_token), str)
def test_get_assignments(self):
self.assertEqual(type(self.client.get_assignments()), list)
def test_generate_two_lists_of_ungraded_assignments(self):
self.assertEqual(type(self.client.generate_two_lists_of_ungraded_assignments()), tuple)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment