gui fix and folder selection

This commit is contained in:
sigvartmh
2017-05-12 17:26:20 +02:00
parent 8c7ee1fdd9
commit 024c09a60f
2 changed files with 26 additions and 6 deletions

24
app.py
View File

@@ -1,5 +1,7 @@
import appJar import appJar
import itl_scrape import itl_scrape
import os
from appJar import gui from appJar import gui
from itl_scrape import itslearning_scraper from itl_scrape import itslearning_scraper
@@ -30,6 +32,12 @@ def select_all(btn):
app.setCheckBox(courses[label], ticked=True, callFunction=False) app.setCheckBox(courses[label], ticked=True, callFunction=False)
print("select all") 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): def press(btn):
user = app.getEntry("feideuser") user = app.getEntry("feideuser")
password = app.getEntry("password") password = app.getEntry("password")
@@ -56,9 +64,18 @@ def press(btn):
app.stopLabelFrame() app.stopLabelFrame()
print(space) print(space)
app.addButton("Download", download, space+2, 0) app.startLabelFrame("Select folder")
app.addButton("Select none", select_none, space+2, 1) app.addButton("Chose folder", select_folder, space+2, 0, 0)
app.addButton("Select all", select_all, space+2, 3) 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.startLabelFrame("It's Learning time")
app.setSticky("ew") app.setSticky("ew")
@@ -71,5 +88,4 @@ app.addSecretEntry("password", 1 , 1)
app.stopLabelFrame() app.stopLabelFrame()
app.addButton("Login", press, 2, 0, 2) app.addButton("Login", press, 2, 0, 2)
app.setFocus("feideuser") app.setFocus("feideuser")
app.go() app.go()

View File

@@ -7,6 +7,7 @@ import html2text
import multiprocessing import multiprocessing
import bs4 import bs4
import getpass import getpass
from multiprocessing import Process from multiprocessing import Process
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as bs
from getpass import getpass from getpass import getpass
@@ -15,6 +16,7 @@ from getpass import getpass
base_url = "https://ntnu.itslearning.com/" base_url = "https://ntnu.itslearning.com/"
folder_url = "https://ntnu.itslearning.com/Folder/processfolder.aspx?FolderID=" folder_url = "https://ntnu.itslearning.com/Folder/processfolder.aspx?FolderID="
def make_folder(curpath, title): def make_folder(curpath, title):
folder_path = os.path.join(curpath,title) folder_path = os.path.join(curpath,title)
#print("making dir:",folder_path) #print("making dir:",folder_path)
@@ -28,8 +30,10 @@ class itslearning_scraper():
self.browser = ms.StatefulBrowser() self.browser = ms.StatefulBrowser()
self.html2text = html2text.HTML2Text() self.html2text = html2text.HTML2Text()
self.start_url = "https://innsida.ntnu.no/lms-ntnu" self.start_url = "https://innsida.ntnu.no/lms-ntnu"
path = os.path.abspath(os.path.curdir) #path = os.path.abspath(os.path.curdir)
newpath = os.path.join(path,"scraped")
def select_path(self, path):
newpath = os.path.join(path, "scraped")
if not os.path.exists(newpath): if not os.path.exists(newpath):
os.makedirs(newpath) os.makedirs(newpath)
os.chdir(newpath) os.chdir(newpath)