Exemple #1
0
def notify():
    subject = "Noen målte nettopp lyset på Fysikkland!"

    text_common = ""
    text_common += "Navigér til <a href=\"http://folk.ntnu.no/hermasl/light\">folk.ntnu.no/hermasl/light</a> for å se målingen!\n"
    text_common += "\n"
    text_common += "Som medlem av Fysikklandlysets epostliste bidrar du til sikker arkivering av lysloggen gjennom et distribuert blockchain-inspirert sikkerhetskopieringssystem.\n"
    text_common += "Du vil derfor finne en kopi av lysloggen under.\n"
    text_common += "Fysikkland anmoder deg om å ta godt vare på kopien i tilfelle noe ufysikalsk inntreffer og den sentrale loggen tilintetgjøres helt eller delvis.\n"
    text_common += "\n"
    text_common += "Fysikkland ønsker deg en fin dag videre.\n"
    text_common += "\n"
    text_common += "--- START LYSLOGG SIKKERHETSKOPI ---\n"
    file = open("light.dat", "r")
    for line in file:
        text_common += line
    file.close()
    text_common += "--- SLUTT LYSLOGG SIKKERHETSKOPI ---\n"

    for subscriber in read_subscribers():
        code = subscriber[0]
        recipient = subscriber[1]
        link = "http://folk.ntnu.no/hermasl/light/unsubscribe.php"
        link += "?email=" + recipient + "&code=" + code
        text_unique = "Dersom du ikke lenger ønsker å varsles når lysslukkingen på Fysikkland registreres, kan du avslutte ditt abonnement <a href=\"%s\">her</a>." % link

        text = text_common + "\n" + text_unique
        text = text.replace("\n", "<br>")

        mail(recipient, subject, text)
Exemple #2
0
        def _nix_bad_emoticons(text):
            """Remove troublesome emoticons so, e.g., '(128)' renders properly.

            By default (at least in 'text' mode), '8)' is replaced by
            a sunglasses-head emoticon.  There is no way to send
            sunglasses-head using alertlib.  This is a feature.
            """
            return text.replace(u'8)', u'8\u200b)')  # zero-width space
Exemple #3
0
        def _nix_bad_emoticons(text):
            """Remove troublesome emoticons so, e.g., '(128)' renders properly.

            By default (at least in 'text' mode), '8)' is replaced by
            a sunglasses-head emoticon.  There is no way to send
            sunglasses-head using alertlib.  This is a feature.
            """
            return text.replace(u'8)', u'8\u200b)')   # zero-width space
Exemple #4
0
def simply_sendmail(host, port, username, password, destination, subject,
                    text):
    smtp = smtplib.SMTP()
    smtp.connect(host, port)
    smtp.starttls()
    smtp.login(username, password)
    msg = email.mime.multipart.MIMEMultipart('alternative')
    msg['From'] = username
    msg['To'] = destination
    msg['Subject'] = subject
    msg.attach(
        email.mime.text.MIMEText(text.replace('\n', '<br>'), 'html', 'utf-8'))
    smtp.sendmail(username, destination, msg.as_string())
Exemple #5
0
def export_one_question(question_base_directory, qi, question, i_variant,
                        variant, topic, tags):

    question_name = "%s_q_%d" % (topic, qi)

    if (len(question.variants) > 1):
        question_name = "%s_v%d" % (question_name, i_variant + 1)

    question_directory = os.path.join(question_base_directory, question_name)
    clientFilesQuestion_directory = os.path.join(question_directory,
                                                 'clientFilesQuestion')

    mkdirOrDie(question_directory)

    question_json_file = os.path.join(question_directory, 'info.json')
    question_html_file = os.path.join(question_directory, 'question.html')

    uuidString = str(
        uuid.uuid5(
            uuid.NAMESPACE_DNS,
            "%s%s%d" % (variant.body, '\n'.join(variant.correct_answers), qi)))

    text = variant.body.rstrip()
    nofig = text.count("\\begin{center}")
    while (nofig > 0):
        mkdirOrDie(clientFilesQuestion_directory)
        start = text.find("\\begin{center}")
        end = text.find("\\end{center}")
        figure_file = os.path.join(clientFilesQuestion_directory, 'figure')
        latex_file = figure_file + '.tex'
        with open(latex_file, 'w') as latex_f:
            latex_f.write("\\documentclass[11pt]{amsart}\n")
            latex_f.write("\\usepackage{tikz}\n")
            latex_f.write(
                "\\usetikzlibrary{snakes,shapes,arrows,shapes.misc}\n")
            latex_f.write("\\pgfrealjobname{figure}\n")
            latex_f.write("\\begin{document}\n")
            latex_f.write("\\beginpgfgraphicnamed{%s}" % question_name)
            latex_f.write(text[start + 14:end - 1])
            latex_f.write("\n")
            latex_f.write("\\endpgfgraphicnamed\n")
            latex_f.write("\\end{document}\n")
        nofig = nofig - 1
        log_and_print("generating figure for question %s" % question_name)
        os.system('pdflatex -jobname=' + question_name +
                  " -output-directory=" + clientFilesQuestion_directory +
                  " -interaction=nonstopmode" + " %s" % figure_file)
        figure_file = os.path.join(clientFilesQuestion_directory,
                                   question_name)
        os.system(
            'gs -dNOCACHE -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile=%s %s'
            % (figure_file + '.png', figure_file + '.pdf'))
        log_and_print("finished generating figure\n")
        fig_html = "<p><pl-figure file-name=\"%s.png\"></pl-figure><p>" % question_name

        text = text.replace(text[start:end + 13], fig_html)

    with open(question_json_file, 'w') as out_f:
        out_f.write("{\n")

        printJsonKeyValue(out_f, "uuid", uuidString)
        printJsonKeyValue(out_f, "title", "Question")
        printJsonKeyValue(out_f, "topic", topic)
        printJsonKeyValueArray(out_f, "tags", tags)
        out_f.write('"type": "v3"\n')
        out_f.write("}")  # end of question object

    with open(question_html_file, 'w') as out_f:
        out_f.write("<pl-question-panel>\n")
        out_f.write(text)
        out_f.write("\n</pl-question-panel>\n")

        element = False
        if (len(variant.correct_answers) > 1):
            element = "pl-checkbox"
        elif (len(variant.correct_answers) == 1):
            element = "pl-multiple-choice"

        if (element):
            out_f.write("<%s answers-name=\"ans\">\n" % element)

            for a in variant.answers:
                out_f.write("<pl-answer")
                if (a.correct):
                    out_f.write(" correct=\"true\"")
                out_f.write(">%s</pl-answer>\n" % a.body)

            out_f.write("</%s>\n" % element)

        if (variant.solution):
            out_f.write("\n<pl-answer-panel><br><br>\n")
            out_f.write(variant.solution)
            out_f.write("\n</pl-answer-panel>\n")

    return question_name
Exemple #6
0
 def translate_line_breaks(text):
     """Convert any EOL style to Linux EOL."""
     text = text.replace("\r\n", "\n")
     return text.replace("\r", "\n")
Exemple #7
0
 def translate_line_breaks(text):
     """Convert any EOL style to Linux EOL."""
     text = text.replace("\r\n", "\n")
     return text.replace("\r", "\n")
Exemple #8
0
	def append(self, text):
		text = text.replace('\n', '')
		self.story.append(text)
		text = text.encode('utf-8')
		print >> self.fd, text
		self.fd.flush()
Exemple #9
0
def export_one_question(question_base_directory, qi, question, i_variant, variant, topic, tags):
   
   question_name = "%s_q_%d" % (topic, qi)
   
   if(len(question.variants)>1):
       question_name =  "%s_v%d" % (question_name, i_variant+1)

   question_directory = os.path.join(question_base_directory , question_name)
   
   mkdirOrDie( question_directory )
   
   question_json_file = os.path.join( question_directory, 'info.json')
   
   uuidString = str( uuid.uuid5(uuid.NAMESPACE_DNS, "%s%s%d" % (variant.body , '\n'.join(variant.correct_answers) , qi ) ))
   q_type = "MultipleChoice";
   if( len(variant.correct_answers) > 1):
      q_type = "Checkbox"
   
   text = variant.body.rstrip()
   nofig = text.count("\\begin{center}")
   files = ["client.js"]
   while (nofig>0): 
      start = text.find("\\begin{center}")
      end   = text.find("\\end{center}")
      figure_file = os.path.join( question_directory, 'figure')
      latex_file = figure_file + '.tex'
      with open(latex_file, 'w') as latex_f:
          latex_f.write("\\documentclass[11pt]{amsart}\n")
          latex_f.write("\\usepackage{tikz}\n")
          latex_f.write("\\usetikzlibrary{snakes,shapes,arrows,shapes.misc}\n")
          latex_f.write("\\pgfrealjobname{figure}\n")
          latex_f.write("\\begin{document}\n")
          latex_f.write("\\beginpgfgraphicnamed{%s}" % question_name) 
          latex_f.write(text[start+14:end-1])
          latex_f.write("\n")
          latex_f.write("\\endpgfgraphicnamed\n")
          latex_f.write("\\end{document}\n")
      nofig = nofig-1
      log_and_print("generating figure for question %s" % question_name)
      os.system('pdflatex -jobname=' + question_name + " -output-directory=" + question_directory + " -interaction=nonstopmode" + " %s" % figure_file)
      figure_file = os.path.join( question_directory, question_name)
      os.system('gs -dNOCACHE -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile=%s %s' % (figure_file + '.png', figure_file + '.pdf'))
      log_and_print("finished generating figure\n")
      fig_html = "<p></p><img src=\"<% print(questionFile(\"" + question_name + ".png\")) %>\" width=\"400px\" class=\"img-responsive center-block\" /><p></p>"
      text = text.replace(text[start:end+13],fig_html)
      files =  files + [question_name + ".png"]
   with open(question_json_file, 'w') as out_f:
      out_f.write("{\n")
      
      printJsonKeyValue(out_f, "uuid", uuidString)
      printJsonKeyValue(out_f, "title", "Question")
      printJsonKeyValue(out_f, "topic", topic)
      printJsonKeyValueArray(out_f, "tags", tags)
      printJsonKeyValueArray(out_f, "clientFiles", files)
      printJsonKeyValue(out_f, "type", q_type)

      out_f.write("\"options\": {\n")     
      printJsonKeyValue(out_f,"text", text)
      printJsonKeyValueArray(out_f, "correctAnswers", variant.correct_answers)
      printJsonKeyValueArray(out_f, "incorrectAnswers", variant.incorrect_answers)
      out_f.write("\"numberAnswers\": %d\n" % len(variant.answers) )
      out_f.write("}\n") # end of options object
      out_f.write("}") # end of question object
      return question_name
Exemple #10
0
def removeUsernameFromDebtMessage(username, text):
    usernameWithTag = '@' + str(username)
    text = text
    if usernameWithTag in text:
        text = text.replace('\n' + usernameWithTag, '', 1)
    return text