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
Mushahid Ali 1 Dec 31, 2021
CoWIN Vaccination slot booking telegram bot with auto captcha resolver & alerting feature.Now, never miss a slot.

COWIN VACCINATION SLOT AUTO BOOKING (Bot with captcha solving & alerting capabilities. Never miss the vaccine slot.) June-10-2021/ 0030 hrs: 23 succes

Shashank Bafna 17 Nov 12, 2022
Account Profiles Dumper for Fortnite.

Fortnite Profile Dumper This program allows you to dump your Fortnite account profiles. How to use it? After starting the FortniteProfileDumper.py, yo

PRO100KatYT 12 Jul 28, 2022
Python client for using Prefect Cloud with Saturn Cloud

prefect-saturn prefect-saturn is a Python package that makes it easy to run Prefect Cloud flows on a Dask cluster with Saturn Cloud. For a detailed tu

Saturn Cloud 15 Dec 07, 2022
Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

WAR MUSIC / VIDEO PLAYER Bot Bot Link: 🧪 Get SESSION_NAME from below: Pyrogram 🎭 Preview ✨ Features Music & Video stream support MultiChat support P

Abhishek singh 11 Dec 25, 2022
基于nonebot2的twitter推送插件

HanayoriBot(Twitter插件) ✨ 基于NoneBot2的Twitter推送插件,自带百度翻译接口 ✨ 简介 本插件基于NoneBot2与go-cqhttp,可以及时将Twitter用户的最新推文推送至群聊,并且自带基于百度翻译的推文翻译接口,及时跟进你所关注的Vtuber的外网动态。

鹿乃まほろ / Mahoro Kano 16 Feb 12, 2022
This is a Anti Channel Ban Robots

AntiChannelBan This is a Anti Channel Ban Robots delete and ban message sent by channels Heroku Deployment 💜 Heroku is the best way to host ur Projec

BᵣₐyDₑₙ 25 Dec 10, 2021
A script to find the people whom you follow, but they don't follow you back

insta-non-followers A script to find the people whom you follow, but they don't follow you back Dependencies: python3 libraries - instaloader, getpass

Ritvik 5 Jul 03, 2022
Cloud-optimized, single-file archive format for pyramids of map tiles

PMTiles PMTiles is a single-file archive format for tiled data. A PMTiles archive can be hosted on a commodity storage platform such as S3, and enable

Protomaps 325 Jan 04, 2023
Disctopia-c2 - Windows Backdoor that is controlled through Discord

Disctopia Disctopia Command and Control What is Disctopia? Disctopia is an open

Dimitris Kalopisis 218 Dec 26, 2022
HinamiRobot - Telegram Group Manager Bot Written In Python Using Pyrogram

✨ HINAMI CHAN ✨ Telegram Group Manager Bot Written In Python Using Pyrogram. Rea

DARK LEGEND088 2 Jan 27, 2022
Discord Bot for League of Legends live match tracker

SABot Dicord Bot for League of Legends match auto tracker Features: Search Summoners statistics in League of Legends. Auto-notifications provide when

Jungyu Choi 4 Sep 27, 2022
Tools for use in DeFi. Impermanent Loss calculations, staking and farming strategies, coingecko and pancakeswap API queries, liquidity pools and more

DeFi open source tools Get Started Instalation General Tools Impermanent Loss, simple calculation Compare Buy & Hold with Staking and Farming Complete

Juan Pablo Pisano 467 Jan 08, 2023
Posts word definitions on Twitter daily

Word Of The Day bot Post daily word definitions on social media. Twitter account: https://twitter.com/WordOfTheDay_B Introduction The goal of this pro

Lucas Rijllart 1 Jan 08, 2022
Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks.

JackrabbitRelay Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks. Disclaimer Please note RA

Rose Heart 23 Jan 04, 2023
Automated endpoint management for Amazon Aurora Global Database

This sample code can be used to manage Aurora global database endpoints. After failover the global database writer endpoints swap from one region to the other. This solution automates creation and ma

AWS Samples 13 Dec 08, 2022
Collection of AWS Fault Injection Simulator (FIS) experiment templates.

Collection of AWS Fault Injection Simulator (FIS) experiment templates. These templates let you perform chaos engineering experiments on resources (applications, network, and infrastructure) in the A

Adrian Hornsby 8 Nov 27, 2022
Example of a discord bot in Python

discordbot.py Example of a discord bot in Python Requirements Python 3.8 or higher Discord Bot Setting Up Clone this repo or download the files Rename

Debert Jamie 1 Oct 23, 2021
A bot which is a ghost and you can make friends with it

This is a bot which is a ghost and you can make friends with it. It will haunt your friends. Explore and test the bot in replit !

Siwan SR 0 Oct 06, 2022
The Python version of the official Discord bot for the Astura Studios Discord community server.

About Astura (Python version) is the official Discord bot for the Astura Studios Discord community server developed and maintained by Ascendus and the

Ascendus 1 Apr 21, 2022