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
An attempt to make a bot that can auto-archive Danganronpa KG RPs on Discord.

Danganronpa Killing Game Archiving Bot An attempt to make a bot that can auto-archive Danganronpa KG RPs on Discord. The final format is meant to look

Astrea 1 Nov 30, 2021
Most Simple & Powefull web3 Trade Bot (WINDOWS LINUX) Suport BSC ETH

Most Simple & Powefull Trade Bot (WINDOWS LINUX) What Are Some Pros And Cons Of Owning A Sniper Bot? While having a sniper bot is typically an advanta

GUI BOT 4 Jan 25, 2022
Automatically check for free Anmeldung appointments.

Berlin Anmeldung Appointments (Python) This Python script will automatically check for free Anmeldung appointments in Berlin, and find them for you. T

Martín Aberastegue 6 May 19, 2022
A repository of publicly verifiable token Sale contracts

Token-Sale-Plutus-Contract A repository of publicly verifiable token sale and royalty contracts. This will be the storage solution since it is easily

Logical Mechanism 29 Aug 18, 2022
Discord Rich Presence implementation for Plex.

Perplex Perplex is a Discord Rich Presence implementation for Plex. Features Modern and beautiful Rich Presence for both movies and TV shows The Movie

Ethan 52 Dec 19, 2022
A telegram bot to forward messages automatically when they arrived.

Telegram Message Forwarder Bot A telegram bot, which can forward messages from channel, group or chat to another channel, group or chat automatically.

Adnan Ahmad 181 Jan 07, 2023
An enhanced discord.py, based off of the now-archived discord.py project

enhanced-discord.py A modern, maintained, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. The Future of enhanced

Devision 2 Dec 21, 2022
A small Python app to create Notion pages from Jira issues

Jira to Notion This little program will capture a Jira issue and create a corresponding Notion subpage. Mac users can fetch the current issue from the

Dr. Kerem Koseoglu 12 Oct 27, 2022
hydrotoolbox is a Python script for hydrologic calculations and analysis or by function calls within Python.

hydrotoolbox is a Python script for hydrologic calculations and analysis or by function calls within Python.

Tim Cera 4 Aug 20, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

1 Oct 28, 2021
🔮 Uncover some followers of a private instagram account

Private Instagram Chaining 🔮 Uncover part of followers of an instagram private account I have this private instagram account julianakhao. I need to g

аэт 69 Dec 17, 2022
Cookies is a project inspired by python cookiecutter but used for terraform generation.

Introduction Cookies is a project inspired by python cookiecutter but used for terraform generation. How to run your terraform After you download your

Digger 6 Mar 14, 2022
A telegram mirror bot with an integrated RSS feed reader.

About What is this repo? This is a slightly modified fork which includes some extra features & memes added to my liking. How's this different from the

11 May 15, 2022
A Bot to Upload files to Many Cloud services. Powered by Telethon.

oVo MultiUpload V1.0 👀 A Bot to Upload files to Many Cloud services. Powered by Telethon _ 🎯 Follow me and star this repo for more telegram bots. @H

32 Dec 30, 2022
Available slots checker for Spanish Passport

Bot that checks for available slots to make an appointment to issue the Spanish passport at the Uruguayan consulate page

1 Nov 30, 2021
YARSAW is an Async Python API Wrapper for the Random Stuff API.

Yet Another Random Stuff API Wrapper - YARSAW YARSAW is an Async Python API Wrapper for the Random Stuff API. This module makes it simpler for you to

Bruce 6 Mar 27, 2022
cipher bot telegram

cipher-bot-telegram cipher bot telegram Telegram bot that encode/decode your messages To work correctly, you must install the latest version of python

anonim 1 Oct 10, 2021
Monitoring plugin for MikroTik devices

check_routeros - Monitoring MikroTik devices This is a monitoring plugin for Icinga, Nagios and other compatible monitoring solutions to check MikroTi

DinoTools 6 Dec 24, 2022
Framework to collect and process weather data from wttr.in.

Weathercrawler Automatic extraction and processing framework for weather data from wttr.in Installation tested with: Python 3.7.3 Python 3.9.4 git clo

Maurice Günder 0 Jul 26, 2021
Play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat 🧪 Get SESSION_NAME from below: Pyrogram

Sehath Perera 1 Jan 17, 2022