Giter VIP home page Giter VIP logo

dsc-canvas-to-git's Introduction

import requests
import os
from dotenv import load_dotenv
load_dotenv()

import markdown
import markdown2
import re 

from canvasapi import Canvas
from canvas_to_git import *

1. Connect to Canvas API

Add Canvas credentials.

  • The API key should be stored in your .env file.
  • Change to the relevant Canvas instance as needed.
canvas_api_key = os.environ.get('CANVAS_TOKEN')
canvas_instance = "https://learning.flatironschool.com"

Connect to Canvas API by creating a Canvas instance.

canvas = Canvas(canvas_instance, canvas_api_key)

2. Locate Course

For all of the methods available for the Course class, see the Course documentation.

To work with an existing course, input a course number.

course_number = 6996
course = canvas.get_course(course_number)
print(course.name)

3. Extract Content

First get the course pages from Canvas.

content = course.get_pages()

Next, use lists to gather the relevant page IDs, page contents, titles, and URLs.

titles = []
page_ids = []
urls = []
contents = []

for page in content:
    pid = page.page_id
    page_ids += [pid]
    p = course.get_page(pid)
    titles += [p.title]
    urls += [p.url]
    contents += [p.body]

Then, extract the titles of lessons and labs only, ignoring any housekeeping/admin pages.

# sanity check
titles
zipped_content = list(zip(titles, page_ids, urls, contents))

# I am using list comprehension here to filter my titles
# but you may want to use another method, or manually generate a list
adj_titles = [title for title in zipped_content 
                if title[0].startswith('๐Ÿ“š Reading:')
                 or title[0].startswith('๐Ÿ”Ž Lab:')]
# sanity check to see what the tuple looks like
adj_titles[0]

4. Mirror Canvas Lessons to GitHub

Run the cell below to create the repo for the first time.

**Change this cell to your course prefix

prefix = None # 'ai-course-XXXX...-'
org_name = 'learn-co-curriculum'
for title in adj_titles:
    repository_name = f'{prefix}{title[2]}'
    organization_name = org_name
    print(repository_name)
    
    # comment out the line below after repos have already been created
    create_github_repository(repository_name, organization_name)
    
    # create/update README
    content = title[3]
    file_path = 'README.md'
    file_title = title[0]
    file_content = f'# {file_title}\n\n{content}'  # Updated content of the file
    commit_message = 'Update file'  # Commit message for the file operation
    create_or_update_file(repository_name, organization_name, file_path, file_content, commit_message)

dsc-canvas-to-git's People

Contributors

christine-egan42 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.