def readposts(self, all=False): """ Read posts from a course's messaging boards """ print cli.courselist() courseId = selectId("Veranstaltung", len(cli.courses) -1) self.asciiout.h1("Posts anzeigen") width = 70 idRange = range(0, len(self.courses)) if all else [courseId] for id in idRange: forumPage = pq(self.read("seminar_main.php?auswahl="+self.courses.keys()[id]+"&redirect_to=forum.php&view=reset&sort=age")) postsPage = pq(self.read("forum_export.php")) posts = postsPage("table td") self.asciiout.h1(self.courses[self.courses.keys()[id]]) # Iterate through the Table with steps of 2. i is the headline, i+1 the body of the post for i in [x for x in range(0, len(posts)-2) if x % 2 ==0]: # Forum headlines have h3-tags forum = posts.eq(i).children("h3").text() if forum: self.asciiout.h2(forum) else: head = posts.eq(i).text() self.asciiout.h3(head) br2nl(posts.eq(i+1)) body = posts.eq(i+1).text() self.asciiout.text(body) self.asciiout.hr()
def readmessages(self, all=False): """ Read all or one message from the messaging system """ self.asciiout.h1("Nachrichten lesen") messagePage = pq(self.read("sms_box.php?mclose=TRUE")) subjects = messagePage("td.printhead a.tree[href*=mopen]") messages = {} def messageList(id): subject = subjects.eq(id) author, date = subject.parents("td.printhead").eq(0).next().text().split(",", 1) messages[id] = { "hash" : fromQueryString(subject.attr("href"), "mopen"), "subject": subject.text(), "author": author.strip().replace("von ", ""), "date": date.strip()} if not all: print self.asciiout.trim("["+str(id)+"] "+messages[id]["author"]+": "+subject.text()) subjects.each(messageList) if not all: id = selectId("Nachricht", len(messages)-1) messages = {id: messages[id]} for message in messages: messagePage = pq(self.read("sms_box.php?mopen="+messages[message]['hash'])) msg = messages[message] self.asciiout.h2(msg["author"]+": "+msg["subject"]+" ("+msg["date"]+")") self.asciiout.text(br2nl(messagePage("td.printcontent")).text()+"\n") if not all: respond = raw_input("Auf diese Nachricht anworten? [j/N] ") if respond in ["j", "J", "y", "Y"]: self.writemessage(answerTo=msg["hash"])
def printNews(i): """ inner function that prints course news """ newsId = fromQueryString(newsItems.eq(i).attr("href"), "nopen") newsPage = pq(self.read("seminar_main.php?nopen="+newsId)) title, rest = newsPage("a[href*=nclose]").parent().siblings().text().split("|", 1) self.asciiout.h2(title) self.asciiout.text(br2nl(newsPage("td.printcontent").eq(1)).text()) self.asciiout.hr()
def courselist(self, indexed=True, standalone=False): """ List courses and display details on demand """ self.asciiout.h1("Meine Veranstaltungen") """ Prints a list of courses """ for i in range(0, len(self.courses)): key = self.courses.keys()[i] if indexed: print "["+str(i)+"] "+self.courses[key] else: print self.courses[key] # courselist() is also utilized by other actions. the standalone flag prevents conflicts if standalone: courseId = selectId("Veranstaltungsdetails", len(self.courses)) coursePage = pq(self.read("seminar_main.php?auswahl="+self.courses.keys()[courseId])) detailPage= pq(self.read("print_seminar.php")) self.asciiout.h1(detailPage("h1").eq(0).text()) rows = detailPage("table").eq(0).find("tr") for i in range(1, len(rows)): tds = rows.eq(i).children("td") self.asciiout.h2(tds.eq(0).text()) self.asciiout.text(br2nl(tds.eq(1)).text())