{"size": 1186, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "0ZeroFive5/timetable-scriptable", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "0ZeroFive5/timetable-scriptable", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "0ZeroFive5/timetable-scriptable", "max_forks_repo_forks_event_min_datetime": "2021-12-01T12:46:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T11:05:19.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 30.4102564103, "max_line_length": 90, "alphanum_fraction": 0.7040472175}
const settings = {
  offset: 0,
  lang: "gr1n",
  wf: "CH",
  angInf: "gr1",
  textColor: Color.white(),
  background: [new Color("#3558cc"), new Color("#a05aa3")],
};

const url = "https://raw.githubusercontent.com/akuvfx/timetable-scriptable/main/main.js";
let modulePath = await downloadModule("timetable", url);
if (modulePath != null) {
  let importedModule = importModule(modulePath);
  await importedModule.main(settings);
} else {
  console.log("Failed to download new module and could not find any local version.");
}

async function downloadModule(scriptName, scriptUrl) {
  let fm = FileManager.local();
  let moduleDir = module.filename.replace(fm.fileName(module.filename, true), scriptName);
  console.log(moduleDir);
  if (fm.fileExists(moduleDir) && !fm.isDirectory(moduleDir)) fm.remove(moduleDir);
  if (!fm.fileExists(moduleDir)) fm.createDirectory(moduleDir);
  let modulePath = fm.joinPath(moduleDir, "main.js");

  console.log("Downloading main.js from URL: " + scriptUrl);

  let req = new Request(scriptUrl);
  let moduleJs = await req.load().catch(() => null);

  if (moduleJs) {
    fm.write(modulePath, moduleJs);
    return modulePath;
  }

  return null;
}
