Пример #1
0
  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"])
Пример #2
0
  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()
Пример #3
0
  def download(self, new=False, all=False):
    """ Download files of a course"""
    courseId = 0
    if not all:
      cli.courselist()
      courseId = selectId("Veranstaltung", len(self.courses) -1)
    self.asciiout.h1("Dateien herunterladen")
    idRange = range(0, len(self.courses)) if all else [courseId]

    for id in idRange:  
      filePage = pq(self.read("seminar_main.php?auswahl="+self.courses.keys()[id]+"&redirect_to=plugins.php&cmd=show&id=19&view=seminarFolders"))
      keyword = ("Neue Dateien " if new else "")+"komprimiert herunterladen"
      downloadLink = filePage('a[title="'+keyword+'"]').eq(0).attr("href")
      courseName = self.courses[self.courses.keys()[id]]

      if downloadLink != None:
        print "Lade Dateien in '"+courseName+"' herunter"
        data = self.read(downloadLink.replace(baseUrl, ""))

        if len(data) > 0:
          fileName = "Downloads/"+safeName(courseName)+".zip"
          if not os.path.exists("Downloads"):
            os.makedirs("Downloads")
          f = open(fileName, "w+")
          f.write(data)
          f.close()
          self.asciiout.text("Dateien in '"+courseName+"' unter "+fileName+" gespeichert")
          self.asciiout.hr()
          continue
      self.asciiout.text("Keine Dateien in '"+courseName+"' gefunden")
      self.asciiout.hr()
Пример #4
0
  def readnews(self, all=False):
    """ Read news for a Course """
    cli.courselist()

    if not all:
      courseId = selectId("Veranstaltung", len(cli.courses) -1)
    width = 70
    idRange = range(0, len(self.courses)) if all else [courseId]

    for id in idRange:  
      self.asciiout.h1("News fuer "+self.courses[self.courses.keys()[id]]+" anzeigen")
      newsPage = pq(self.read("seminar_main.php?nclose=TRUE&auswahl="+self.courses.keys()[id]))
      newsItems = newsPage("a[href*=nopen]").children("img").parent()

      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()
      newsItems.each(printNews)
Пример #5
0
  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())