A bot that downloads all the necessary files from WeLearn and lists your assignments, filter due assignments, etc.

Overview

Welearn-bot

This is a bot which lets you interact with WeLearn from the command line. It can

  • Download all files/resources from your courses and organize them in designated folders.
  • Show your assignments, filter due assignments.
  • Add your assignments to Google Calendar.

Go to our project wiki to learn more about configuring and using the script. Developers may be interested in the article on using the Moodle Web Service module, which shows you how to use the accompanying moodlews.service module to write your own script for interacting with WeLearn, or indeed any other Moodle service.

Demo

asciicast

Installation

This script runs on python3. To install it on your system, run

pip install --upgrade welearn-bot-iiserkol

The --upgrade flag ensures that you get the latest version.

If you are on Windows and are new to python, please go through this quick guide.

Running from source

Clone this repo or download the source code, and navigate to that directory. To install dependencies, run

pip install -r requirements.txt

You can now navigate to the src directory and run python welearn_bot [options ...].

Configuration

On *nix systems (linux, macos), create a ~/.welearnrc file; on Windows, create a welearn.ini in your C:/Users/USERNAME/ folder. Inside, fill in your details in the following format.

[auth]
username = AzureDiamond
password = hunter2

[courses]
MA1101
PH2202
CH3303
LS4404
ES5505

You may omit any or all of your [auth] credentials, in which case you will be prompted each time you run the program.

There are many more configuration options to explore, such as the [files] and [gcal] sections - for a detailed breakdown, please consult our wiki page on writing your configuration file.

Google calendar integration

Integration with Google Calendar is completely optional. This feature allows you to save your assignment dates directly to Google Calendar, when you use the --gcalendar option. You can also choose which calendar within your Google Calendar account to push events to.

You will have to authenticate using OAuth2.0 and add some lines to your configuration file. Please follow the steps in the Google Calendar integration article. At the end, your configuration file will have a section of the following form.

[gcal]
client_id = xxxxxxxxxxxxxxx.apps.googleusercontent.com
client_secret = xxxxxxxxxxxxxxxxx
calendar_id = [email protected]

Usage

Run welearn_bot -h to get the following help message.

usage: welearn_bot [-h] [-v] [-d] [-c] [-i [IGNORETYPES ...]] [-f] [-p PATHPREFIX] action [courses ...]

A command line client for interacting with WeLearn.

positional arguments:
  action                choose from
                            files       - downloads files/resources
                            assignments - lists assignments, downloads attachments
                            urls        - lists urls
                            courses     - lists enrolled courses
                            whoami      - shows the user's name and exits
                        Abbreviations such as any one of 'f', 'a', 'u', 'c', 'w' are supported.
  courses               IDs of the courses to download files from. The word ALL selects everything
                        from the [courses] section in .welearnrc or welearn.ini

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -d, --dueassignments  show only due assignments with the 'assignments' action
  -c, --gcalendar       add due assignments to Google Calendar with the 'assignments' action
  -i [IGNORETYPES ...], --ignoretypes [IGNORETYPES ...]
                        ignores the specified extensions when downloading, overrides .welearnrc
  -f, --forcedownload   force download files even if already downloaded/ignored
  -p PATHPREFIX, --pathprefix PATHPREFIX
                        save the downloads to a custom path, overrides .welearnrc

See our article on using command line options for a detailed breakdown.

Examples

Testing your setup

If your .welearnrc or welearn.ini file is set up correctly, the following command should simply display your name.

welearn_bot whoami

To get a list of courses you are enrolled in, run

welearn_bot courses

Basic commands

To pull all files from the courses MA1101 and CH3303, run

welearn_bot files MA1101 CH3303

You can use the shorthand f for files, so the following is an equivalent command.

welearn_bot f MA1101 CH3303

To show assignments and download their attachments from the course MA1101, run

welearn_bot assignments MA1101

To list due assignments (due date in the future) from all courses, run

welearn_bot -d assignments ALL

Make sure that the -d flag comes first!

To list all urls from the CH3303 course, run

welearn_bot urls CH3303

Calendar integration

To list due assignments from all courses, and add them to your calendar, run

welearn_bot -dc assignments ALL

Ignoring filetypes

To download all resources from the course CH3303, ignoring pdf files, run

welearn_bot -i pdf -- files CH3303

Note the use of -- which is essential for separating the IGNORETYPES from the courses. The following format may be preferred.

welearn_bot files CH3303 -i pdf

To override the .welearnrc ignore settings and allow all extensions, but still respect past downloads, run

welearn_bot -i -- files CH3303

Force downloads and pathprefix

To force download all resources from the course PH2202, even if already downloaded and present or set to be ignored, and put all the course directories in the ~/notes folder, run

welearn_bot files PH2202 -fp ~/notes 
Comments
  • security issue: the program is vulnreable as password is saved in plain text on the machine.

    security issue: the program is vulnreable as password is saved in plain text on the machine.

    Anyone with access to my machine can read the password as it is saved in plain text. There should be an option for the program to prompt for the password if the user does not save his/her password in welearnrc

    opened by nick-nds 2
  • Enhancement: Add ability to mention a custom path where the can be downloaded.

    Enhancement: Add ability to mention a custom path where the can be downloaded.

    Why?

    Given that this is to be used as a script. One should be able to run it from anywhere and store the files in a predefined path. As of now, it downloads them in the directory from where the script is run.

    Possible features:

    • A prefix setting in preference section in .welearnrc
    • A -p flag while running the script to save to a custom path. This should overwrite the prefix if already set in .welearnrc

    PS: I was about to implement this but @sahasatvik is working on switching to using moodle API. This would change the details of the implementation. I would start after all such major changes are done.

    opened by MASTERAMARJEET 2
  • Fetch students' assignment submissions (TAs)

    Fetch students' assignment submissions (TAs)

    Feature for TAs

    This PR adds the capability for TAs to fetch assignment submissions from welearn.

    Notable features

    • The assignments for each subject are downloaded into it's own submissions folder.
    • Each student has it's own folder for each assignment.
    • If the assignment are in archived form (compressed), they are automatically uncompressed.

    Config changes

    The users will have to add a [submissions] section to their config with the appropriate information (as shown below)

    [submissions]
    CS1103 = ALL
    CS1101 = 21MS020, ... , 21MS120
    CS1102 = 21MS120,  21MS121,  21MS122,  21MS123,  21MS124,  21MS125,  21MS126
    CS1101 = 20MS011,  19MS112, 21MS020, ... , 21MS120
    

    Note that you have to add key value pairs of courseid and the roll numbers for which to fetch the submissions The roll numbers can be entered in the following form:

    • ALL to fetch all submissions
    • a range of roll numbers
    • a explicit list of roll numbes
    • a mix of range and explicit roll numbers

    CLI arguments

    • An additional action, s (submissions) has been exposed to the users for using this feature
    • The users can also specify list of roll numbers from the cli using -r (--rolls) option
    • CLI arguments override the config settings

    Misc

    A new cache for course information is also added. The users can update the cache using the -u flag

    enhancement 
    opened by MASTERAMARJEET 0
  • Refactor welearnbot.py

    Refactor welearnbot.py

    Refactoring welearnbot.py

    This refactor separates the logic being handled into functions using the functional programming approach. This will give the script a pipeline like behaviour while keeping it extendable.

    The following refactors were done.

    • move the parser setup to a separate function
    • move constants(like config location, etc.) into separate files so that they are accessible everywhere
    • create (resolver) functions for getting information from config , input, server, etc
    • isolate code for handling each action into handler functions (handle_action)
    opened by MASTERAMARJEET 0
  • Google calendar integration

    Google calendar integration

    Feature

    This introduces the --gcalendar flag with the assignments action, which will add due assignments to the user's Google Calendar of choice. You can run

    welearn_bot -dc assignments ALL
    

    to add all due assignments to your Google Calendar, after appropriate configuration.

    The duration of the created event extends one hour before the deadline, up to the deadline. This choice was made so that the user gets some level of notification before the deadline, and because logically the event ought to end when the deadline is reached.

    The user can also choose a "sub calendar" within their Google Calendar account to push events. This gives an additional layer of control, whereby calendarwide preferences such as event colour, notification settings, visibility/sharing, etc can be configured directly from Google Calendar.

    Thanks to @AK6263 for contributing the base code for connecting the the Google Calendar API and pushing events.

    Caveats

    Using this feature requires a fairly complicated process of authentication, which includes the creation of tokens from the Google Developer Console. Complete details are present in the updated README.md. In addition, the program triggers an OAuth login page which opens in the browser if the refresh token expires, which happens roughly every 7 days.

    Since this particular feature cannot be automated to the same level as the other actions, Google Calendar integration has been kept as unintrusive and optional as possible.

    Changes

    • The --gcalendar flag has been added, along with functionality for using the Google Calendar API via OAuth 2.0.
    • The [gcal] section has been added to the config file, which must have the client_id and client_secret keys for authenticating with the Google Calendar API.
    • The optional calendar_id key specifies the particular calendar within Google Calendar to which events are to be added.
    enhancement 
    opened by sahasatvik 0
  • Moodle Webservice module

    Moodle Webservice module

    The core server functions, such as authentication and fetching of JSON records, have been encapsulated into a moodlews.service module. This is to streamline the flow of the code, and emphasize that WeLearn is one of many Moodle services that our script can potentially work with.

    A typical usecase is as follows.

    from moodlews.service import MoodleClient
    from moodlews.service import ServerFunctions as sf
    
    # Create the client and authenticate
    moodle = MoodleClient("https://welearn.iiserkol.ac.in/")
    token = moodle.authenticate("username", "password")
    
    # Empty token if login failed
    if not token:
        ....
    
    # Fetch site info records
    site_info = moodle.server(sf.SITE_INFO)
    userid = site_info["userid"]
    
    # Fetch user enrolled courses
    user_courses = moodle.server(sf.USER_COURSES, userid=userid)
    ....
    

    Changes

    • Altered directory structure, with a src folder.
    • Creation of a moodlews.service module, with the MoodleClient and ServerFunctions classes.
    • Implementation of the same into welearn_bot
    opened by sahasatvik 0
  • Command line arguments - modes/actions instead of flags

    Command line arguments - modes/actions instead of flags

    Why?

    The welearn-bot client can only perform one action per run, such as fetching files, listing assignments, etc. Thus, it doesn't make sense to allocate fetching files as a default, and leave the others as command line options, of which at most one can be used at a a time. Instead, we can specify a single mode/action to perform, such as files or assignments, which helps make the desired outcome more explicit.

    Summary of actions

    Following are the implemented actions.

    • files: all resources and files from the specified courses will be downloaded.
    • assignments: all assignments from the specified courses will be listed, and the attachments will be downloaded.
    • urls: all urls from the specified courses will be listed.
    • courses: all enrolled courses will be listed
    • whoami: this is a command to retrieve the user's name from the server (mostly used to check that the program has been configured properly)
    usage: welearn_bot [-h] [-d] [-i [IGNORETYPES ...]] [-f] [-p PATHPREFIX] action [courses ...]
    
    A command line client for interacting with WeLearn.
    
    positional arguments:
      action                choose from
                                files       - downloads files/resources
                                assignments - lists assignments, downloads attachments
                                urls        - lists urls
                                courses     - lists enrolled courses
                                whoami      - shows the user's name and exits
                            Abbreviations such as any one of 'f', 'a', 'u', 'c', 'w' are supported.
      courses               IDs of the courses to download files from. The word ALL selects everything from the [courses] section in .welearnrc or welearn.ini
    
    optional arguments:
      -h, --help            show this help message and exit
      -d, --dueassignments  show only due assignments with the 'assignments' action
      -i [IGNORETYPES ...], --ignoretypes [IGNORETYPES ...]
                            ignores the specified extensions when downloading, overrides .welearnrc
      -f, --forcedownload   force download files even if already downloaded/ignored
      -p PATHPREFIX, --pathprefix PATHPREFIX
                            save the downloads to a custom path, overrides .welearnrc
    

    Some common operations are

    ./welearn_bot.py files MA1101        # Get files from MA1101
    ./welearn_bot.py -d assignments ALL  # Show all due assignments
    ./welearn_bot.py -d a ALL            # Same as above
    

    Please see the updated README.md for a full list of examples.

    enhancement 
    opened by sahasatvik 0
  • Switching to the Moodle Web Service API

    Switching to the Moodle Web Service API

    Why?

    The Moodle webservice API is much faster than scraping webpages one by one and parsing HTML. Furthermore, the API returns a complete list of files which solves the problem of nested resources.

    Why not?

    There are a few details about assigments (submission status) which have not yet been implemented.

    Changes

    • Restructured all code to work with the webservice API, which gives a significant speed boost
    • Restructured the .welearnrc format
    • Changed the level of detail of assignment statuses
    • The bot now downloads assignment attachments
    opened by sahasatvik 0
  • How about a more structured format for welearnrc?

    How about a more structured format for welearnrc?

    Why?

    When we think of rc files, bashrc or vimrc, etc comes to our mind. They all have some variable-value kind of setup so that the meaning of each setting can be better conveyed to the user. I tried to achieve the same.

    How?

    Python has a built-in configparser module that can parse .ini config files. So I chose to use .ini formatting for the .welearnrc file. This can then be easily parsed using the aforementioned module.

    Changes:

    • Updated README.md to convey to the users to use the new format.
    • Implemented .welearnrc parsing using the configparser module.

    NOTE: Merging this into main will break the code until the user updated the .weleanrc file to use the new format.

    opened by MASTERAMARJEET 0
  • Fixing attribute error

    Fixing attribute error

    Traceback (most recent call last): File "/home/parth/.local/bin/welearn_bot", line 8, in sys.exit(main()) File "/home/parth/.local/lib/python3.8/site-packages/welearnbot/welearnbot.py", line 58, in main handler.handle_files( File "/home/parth/.local/lib/python3.8/site-packages/welearnbot/action_handlers.py", line 185, in handle_files modules = item.get("modules", []) AttributeError: 'str' object has no attribute 'get'

    opened by ParthBibekar 1
  • The files that were uploaded on the welearn in the discussion forum is not getting downloaded when running the command 'welearn_bot files ALL'

    The files that were uploaded on the welearn in the discussion forum is not getting downloaded when running the command 'welearn_bot files ALL'

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    enhancement wontfix 
    opened by SaqlainAfroz 0
Releases(v1.3.0)
  • v1.3.0(Aug 26, 2022)

    Feature: Support for TAs have been added.

    • An additional action, s (submissions) has been exposed to the users for using this feature
    • New flags -u and -r (--rolls) have been added.

    To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.5(Mar 7, 2022)

    Feature: use -v or --verbose to list missing/ignored files while downloading (these are suppressed by default).

    Dev: major code refactor.

    To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.4(Jan 29, 2022)

    Fix: files in cache (downloaded previously) but not on disk are listed as 'missing'.

    Feature: use --missingdownload or -m to (re)download these missing files.

    To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(May 4, 2021)

    Fix: fetching assignment submissions no longer crashes on the first try.

    To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Apr 14, 2021)

    Fix: download and ignore messages are now more consistent, with the currently downloading file name displayed in advance.
    Info: you can now run welearn_bot --version or welearn_bot -v to display the installed version.
    The project structure has also been reshuffled so that welearn_bot is no longer a script, but is instead called from the welearnbot.welearnbot module.

    To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Apr 12, 2021)

    Fix: the script can now detect and download content from folders within course pages. To make sure that you have this patch installed, run

    pip install --upgrade welearn-bot-iiserkol
    

    Support for this script on Windows is still being tested. If you are running Windows and you do not have python on your system, consider going through this quick guide. Otherwise, you are advised to download the source files, present in the src directory, and execute welearn_bot using whatever python environment you have present.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Apr 12, 2021)

    This release features big changes!

    • We now have Google Calendar integration! You can now add all your assignments to your calendar with a single command. See our wiki article for more info.
    • The core functionality of the script has been packaged into the moodlews.service module, which you can import and use to write your own scripts for interfacing with WeLearn, or any other Moodle service. Read out article on using the Moodle Web Service module for details.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Apr 10, 2021)

    You can now omit your [auth] credentials, in which case you will be prompted each time you run the program. You may also choose not to have a config file at all.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 10, 2021)

    First major release of welearn_bot.py. Install it with

    pip install welearn-bot-iiserkol
    

    Highlights include

    • Actions to retrieve files, assignments, urls and courses.
    • A configuration file (.welearnrc or welearn.ini) to store user authentication data along with preferences.
    • Use of the Moodle Web Services API for speedy retrieval of information.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0a1(Apr 10, 2021)

Owner
Parth Bibekar
Undergraduate at IISER Kolkata
Parth Bibekar
Spotify Top Lists - get the current top lists of a user from the Spotify API and display them in a Flask app

Spotify Top Lists This is a simple script that will get the current top lists of a user from the Spotify API and display them in a Flask app. Requirem

Yasin 0 Oct 16, 2022
An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot

Adv Auto Filter Bot V2 This Is Just An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot.. Just Sent Any Text As Query It Wi

null 0 Dec 18, 2021
A Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot

Adv Auto Filter Bot This Is Just An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot.. Just Sent Any Text As Query It Will

TeamShadow 4 Dec 10, 2021
A simple python script to send files into your telegram Bot form your PC, Server etc.

telegramSend A simple python script to send files into your telegram Bot form your PC, Server etc. How to Use Install requirements.txt pip3 install -r

Ajay Kumar Tekam 1 Jul 19, 2022
KalmanFilterExercise - A Kalman Filter is a algorithmic filter that is used to estimate the state of an unknown variable

Kalman Filter Exercise What are Kalman Filters? A Kalman Filter is a algorithmic

null 4 Feb 26, 2022
Due to changes to the discord API and discord.py being discontinued

Talia Due to changes to the discord API and discord.py being discontinued, Talia development has been halted permanently A customizable economy discor

null 2 Mar 8, 2022
Linky bot, A open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

LinkyBot Linky bot, An open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

AlexyDaCoder 1 Sep 20, 2022
StudyLion is a Discord bot that tracks members' study and work time while offering members to view their statistics and use productivity tools such as: To-do lists, Pomodoro timers, reminders, and much more.

StudyLion - Discord Productivity Bot StudyLion is a Discord bot that tracks members' study and work time while offering members the ability to view th

null 45 Dec 26, 2022
szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szsupunma 93 Jan 7, 2023
Using twitter lists as your feed

Twitlists A while ago, Twitter changed their timeline to be algorithmically-fed rather than a simple reverse-chronological feed. In particular, they p

Peyton Walters 5 Nov 21, 2022
A Discord bot to allow people to create lists of random characters, with limit reroll options.

Mugen Bot A small bot I made to practice python and allow people to publically select random characters on a discord server. Uses py-cord, as that is

Haley 2 Feb 6, 2022
Telegram Bot to Filter posts in Bot Inline search

Inline-Filter-Bot A Telegram Bot for filter in Inline Features Unlimited Filters Supports all type of filters Supports Alert Button Using Common Marku

Code X Botz 67 Dec 26, 2022
Very Sempil Bot Auto Filter bot

SAMANTHA_BOT Very Sempil Bot Auto Filter bot ##[ # ?????????? ?????????? ?????????? ???? ???????????? ?? ?? ?? Auto Filter Manuel Filter IMDB Admin Co

DARK WEBLOAD 3 Jun 27, 2022
Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & runs for 24x7 hours.

PowerfulBotStatus-IDN-C-X Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & ru

IDNCoderX 5 Oct 6, 2022
Signs the target email up to over 1000 different mailing lists to get spammed each day.

Email Bomber Say goodbye to that email Features Signs up to over 1k different mailing lists Written in python so the program is lightweight Easy to us

Loxdr 1 Nov 30, 2021
A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

AMIT 29 Jan 1, 2023
Unofficial instagram API, give you access to ALL instagram features (like, follow, upload photo and video and etc)! Write on python.

Instagram-API-python Unofficial Instagram API to give you access to ALL Instagram features (like, follow, upload photo and video, etc)! Written in Pyt

Vladimir Bezrukov 1 Nov 19, 2021
google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Google APIs 36 Nov 22, 2022