From 024c09a60f47377063805a32a4cf5c3fa6bf21b2 Mon Sep 17 00:00:00 2001 From: sigvartmh Date: Fri, 12 May 2017 17:26:20 +0200 Subject: [PATCH] gui fix and folder selection --- app.py | 24 ++++++++++++++++++++---- itl_scrape.py | 8 ++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 64c706c..12df90c 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,7 @@ import appJar import itl_scrape +import os + from appJar import gui from itl_scrape import itslearning_scraper @@ -30,6 +32,12 @@ def select_all(btn): app.setCheckBox(courses[label], ticked=True, callFunction=False) print("select all") +def select_folder(btn): + path = app.directoryBox(title="Folder to save into", dirName=None) + print(path) + app.setLabel("path", path) + scraper.select_path(path) + def press(btn): user = app.getEntry("feideuser") password = app.getEntry("password") @@ -56,9 +64,18 @@ def press(btn): app.stopLabelFrame() print(space) - app.addButton("Download", download, space+2, 0) - app.addButton("Select none", select_none, space+2, 1) - app.addButton("Select all", select_all, space+2, 3) + app.startLabelFrame("Select folder") + app.addButton("Chose folder", select_folder, space+2, 0, 0) + path = os.path.abspath(os.path.curdir) + app.addLabel("path", path, space+2, 1) + app.stopLabelFrame() + app.startLabelFrame("Optional Actions") + app.addButton("Select none", select_none, 0, 0, 0) + app.addButton("Select all", select_all, 0, 1, 0) + app.stopLabelFrame() + app.startLabelFrame("Final step") + app.addButton("Download", download, 0, 0, 2) + app.stopLabelFrame() app.startLabelFrame("It's Learning time") app.setSticky("ew") @@ -71,5 +88,4 @@ app.addSecretEntry("password", 1 , 1) app.stopLabelFrame() app.addButton("Login", press, 2, 0, 2) app.setFocus("feideuser") - app.go() diff --git a/itl_scrape.py b/itl_scrape.py index 7a1a25f..7bd2070 100644 --- a/itl_scrape.py +++ b/itl_scrape.py @@ -7,6 +7,7 @@ import html2text import multiprocessing import bs4 import getpass + from multiprocessing import Process from bs4 import BeautifulSoup as bs from getpass import getpass @@ -15,6 +16,7 @@ from getpass import getpass base_url = "https://ntnu.itslearning.com/" folder_url = "https://ntnu.itslearning.com/Folder/processfolder.aspx?FolderID=" + def make_folder(curpath, title): folder_path = os.path.join(curpath,title) #print("making dir:",folder_path) @@ -28,8 +30,10 @@ class itslearning_scraper(): self.browser = ms.StatefulBrowser() self.html2text = html2text.HTML2Text() self.start_url = "https://innsida.ntnu.no/lms-ntnu" - path = os.path.abspath(os.path.curdir) - newpath = os.path.join(path,"scraped") + #path = os.path.abspath(os.path.curdir) + + def select_path(self, path): + newpath = os.path.join(path, "scraped") if not os.path.exists(newpath): os.makedirs(newpath) os.chdir(newpath)