Using command line options - ParthBibekar/Welearn-bot GitHub Wiki
After you've installed welearn_bot
, say using pip install welearn-bot-iiserkol
, you can run welearn_bot -h
in the command line
to get the following help message. This gives a summary of the commands and options which you can use.
usage: welearn_bot [-h] [--version] [-v] [-d] [-c] [-i [IGNORETYPES ...]] [-f]
[-m] [-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
options:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbose show verbose warnings/errors
-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
-m, --missingdownload
re-download those files which were downloaded earlier but deleted/moved from their location
-p PATHPREFIX, --pathprefix PATHPREFIX
save the downloads to a custom path, overrides .welearnrc
Here, we will go through each "action" and their possible variations one by one.
whoami
Even if you have a completely fresh install of welearn_bot
without having written a configuration file, you can run
welearn_bot whoami
in the command line. You will be prompted for your username and password, and if everything is set up correctly, the script will display your full name and exit. This is mostly intended for testing your setup and configuration file, so that you know everything works before looking into other commands.
Every action can be abbreviated to any extent, so the following are all equivalent.
welearn_bot whoami
welearn_bot who
welearn_bot w
courses
This action will list all the courses you are enrolled in, marking your starred courses with an asterisk (*
).
welearn_bot courses
Note that this is different from the [courses]
section in your config file. The latter is a list of courses which you have chosen to act as shorthand for ALL
. This is so that when
performing other actions such as files
or assignments
, you do not have to type out a complete list of all your courses.
files
This action will download all available resources for a list of specified courses. For example,
welearn_bot files MA1101 PH2202 CH3303
will download all files from the three listed courses and put them into separate directories of the same name. Note that the script is smart enough to detect whether a file has been downloaded before, or whether the file has been updated on WeLearn.
You may also run
welearn_bot files ALL
to pull files from ALL
courses - again, look into the wiki on the courses section in your config file.
pathprefix
By default, your course folders are created in the same directory you run the script in. If you want to specify a particular
directory in which to organize all your files, you can use the pathprefix
option by either
- setting the
pathprefix
key in the[files]
section in your config file. - passing the
--pathprefix
option in the command line, which overrides your config file. For example, if you want your course directories to appear in the~/Documents/WeLearn
directory, you may run
welearn_bot --pathprefix ~/Documents/WeLearn files ALL
Note that this can be shortened to
welearn_bot -p ~/Documents/WeLearn f ALL
ignore
You may choose to ignore files of certain extensions while downloading, say mp4
or mkv
files. Like before, you can do this using the
ignore
option by
- setting the
ignore
key in the[files]
section in your config file. - passing the
--ignore
option in the command line, which overrides your config file. For example, if you want to ignoremp4
andmkv
files, you can run either one of the following.
welearn_bot --ignore mp4 mkv -- files ALL
welearn_bot files ALL --ignore mp4 mkv
welearn_bot f ALL -i mp4 mkv
forcedownload
The --forcedownload
command line flag will force all downloads, regardless of whether the resource has already been downloaded, or whether
the particular filetype is set to be ignored.
missingdownload
The --missingdownload
command line flag will re-download files which were already downloaded by welearn_bot
at some point, but are no longer present (perhaps subsequently deleted/moved). Without this flag, such missing files are ignored, and not downloaded.
verbose
When downloading files, welearn_bot
will let you know how many files are missing or have been ignored. You can rerun the same command with the --verbose
flag to list these files.
assignments
This action will list all the assignments, both past and present, in the specified courses. It will also download any "attachments" - resources which are attached to the assignment page. For example,
welearn_bot assignments MA1101 PH2202
will list and download all assignments in the MA1101
and PH2202
courses.
Since this action downloads files to their course directories, the pathprefix
, ignore
, and force
options apply, just as before.
In addition, you have the following options
dueassignments
The --dueassignments
command line flag will only list and download attachments from "due" assignments. Here, the phrase "due assignments"
is used loosely, in the sense "assignments whose due dates are in the future". Note that even if you have made submissions to a particular
assignment, it may still be listed as due. This shouldn't cause confusion, however, since the script also lists all the files
you have submitted (if any) for each assignment, along with the time of their upload.
The following are equivalent.
welearn --dueassignments assignments ALL
welearn -d a ALL
gcalendar
The --gcalendar
command line flag invokes the Google Calendar API and adds your due assignments to your Google Calendar.
Each assignment is given an event with the title of your course and the assignment name, along with your assignment details in the body.
The start time of the event is set to one hour before the deadline, and the end time is the deadline itself.
See the Google Calendar integration article on how
to get started. Note that you must have a proper configuration before using this flag.
The following are equiavelent.
welearn_bot --dueassignments --gcalendar assignments ALL
welearn_bot -dc a ALL
urls
The urls
action will list all urls given in the course pages specified. These are typically things like links to recorded videos,
lecture material, or external resources. For example,
welearn_bot urls MA1101 PH2202
will list all urls in the MA1101
and PH2202
courses.