Skip to content

pczern/tum-get

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tum-get

Download all Zips for your specified courses on Moodle, then move them based on a pattern or just leave them in the root folder.

Features

  • Concurrent Downloads 🔀
  • Extract Zips 📁
  • Pattern Matching 🔍
  • Filename Matching
  • Negative Patterns
  • Display New Files (not comparing dates, just filenames)
  • Open Source

Run

Download the binary & run it within the same folder as input.json.

./tum-get # when you download the binary rename it or add version, os and architecture to the name

You can also skip fetching the zip files from Moodle and just use the file pattern matching capabilities.

./tum-get -skip-fetch

Examples

Save the json in a file called input.json.

Simple

Downloads the course's zip to the moodle folder.

{ 
  "username": "username",
  "password": "password",
  "root": "/Users/user/uni/moodle",
  "data": [
    {
      "course": "Course 1",
      "url": "https://www.moodle.tum.de/local/downloadcenter/index.php?courseid=xxxxx",
     
    },
  ]
}

Intermediate

Downloads the course's zip and use Golang filepath.Match to match all files in a course that contain solutions* in the filename, and then copies them to sorted/course1/solutions.

{ 
  "username": "username",
  "password": "password",
  "root": "/Users/user/uni/moodle",
  "data": [
    {
      "course": "Course 1",
      "url": "https://www.moodle.tum.de/local/downloadcenter/index.php?courseid=xxxxx",
      "rules": [{
        "method": "copy",
        "file_pattern": "solutions*",
        "dest": "/Users/user/uni/sorted/course1/solutions"
      }]
    },
  ]
}

Advanced

Downloads the course's zip and matches by regex all paths that have a "solutions" string but not a "solutions2" string, and copies them. The negative patterns are added because negative lookaheads are not supported out of the box. input.json

{ 
  "username": "username",
  "password": "password",
  "root": "/Users/user/uni/moodle",
  "data": [
    {
      "course": "Course 1",
      "url": "https://www.moodle.tum.de/local/downloadcenter/index.php?courseid=xxxxx",
      "rules": [{
        "method": "copy",
        "regex_path_pattern": "^.*solutions.*$",
        "neg_regex_path_pattern": "^.*solutions2.*$",
        "dest": "/Users/user/uni/sorted/course1/solutions"
      }]
    }
  ]
}

All possible patterns

Matches paths and filenames against many patterns and then moves the file instead of copying it when all matches succeed. An empty placeholder file is created for each moved file. input.json

{ 
  "username": "username",
  "password": "password",
  "root": "/Users/user/uni/moodle",
  "data": [
    {
      "course": "Course 1",
      "url": "https://www.moodle.tum.de/local/downloadcenter/index.php?courseid=xxxxx",
      "rules": [{
        "method": "rename",
        "file_pattern": "solutions*",
        "path_pattern": "solutions1*",
        "neg_file_pattern": "solutions2*",
        "neg_path_pattern": "solutions2*",
        "regex_file_pattern": "^.*solutions.*$",
        "regex_path_pattern": "^.*solutions.*$",
        "neg_regex_file_pattern": "^.*solutions2.*$",
        "neg_regex_path_pattern": "^.*solutions2.*$",
        "dest": "/Users/user/uni/sorted/course2/solutions"
      }]
    }
  ]
}

Note that path_patterns match the full path, and file_patterns match only the basenames of the files.
All patterns are matched for files in a rule before the file is written to dest.

method can be copy or rename.
rename moves the matched files to dest and creates a placeholder file where the original was.
copy copies the files to dest, a placeholder is not created.
New files that are not in the file system yet are outputted to the console, this is why rename creates a placeholder so that the program knows that the file already existed.<br The folders in input.json are auto-generated.

Tips

The tool poppler-utils has a utility called pdfunite. You can install poppler-utils to merge multiple PDFs from the command line. The bash script script.sh merges multiple PDFs in subdirectories. It's recommended to use it with an input.json config that has a two level structure for dest like /sorted/course/solutions, /sorted/course/exercises.

brew install poppler # install poppler-utils
./script.sh /Users/user/uni/sorted # merge PDFs in subdirectories of folder "sorted"
cd /Users/user/uni/sorted
ls # view merged PDFs

Bulid and Run from Source Code

To build from source install Golang, build the binary for your system & run it within the same folder as input.json.

go build .
./tum-get

About

Download ZIP files from Moodle, sort them by patterns

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published