Beispiel #1
0
    def do_POST(self):
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    "REQUEST_METHOD": "POST",
                                    "CONTENT_TYPE":
                                    self.headers["Content-Type"]
                                })
        result = "NOT_UNDERSTOOD"

        if self.path == "/refresh":
            # recompute jsons. We have to pop out to root from render directory
            # temporarily. It's a little ugly
            refresh_time = form.getvalue("time")
            os.chdir(rootdir)  # pop out
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..",
                                  "render"))  # pop back to render directory
            result = "OK"

        if self.path == "/addnote":
            # add note at specified time and refresh
            note = form.getvalue("note")
            note_time = form.getvalue("time")
            os.chdir(rootdir)  # pop out
            os.system("echo %s | ../scripts/note.sh %s" % (note, note_time))
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..", "render"))  # go back to render
            result = "OK"

        if self.path == "/blog":
            # add note at specified time and refresh
            post = form.getvalue("post")
            if post is None:
                post = ""
            post_time = int(form.getvalue("time"))
            os.chdir(rootdir)  # pop out
            trev = rewindTime(post_time)
            with open(
                    os.path.join("..", "logs", "blog_%d.txt" % (post_time, )),
                    "w") as f:
                f.write(post)
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..", "render"))  # go back to render
            result = "OK"

        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(result)
Beispiel #2
0
    def do_POST(self):
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    'REQUEST_METHOD': 'POST',
                                    'CONTENT_TYPE':
                                    self.headers['Content-Type']
                                })
        result = 'NOT_UNDERSTOOD'

        if self.path == '/refresh':
            # recompute jsons. We have to pop out to root from render directory
            # temporarily. It's a little ugly
            refresh_time = form.getvalue('time')
            os.chdir(rootdir)  # pop out
            updateEvents()  # defined in export_events.py
            os.chdir('render')  # pop back to render directory
            result = 'OK'

        if self.path == '/addnote':
            # add note at specified time and refresh
            note = form.getvalue('note')
            note_time = form.getvalue('time')
            os.chdir(rootdir)  # pop out
            os.system('echo %s | ./note.sh %s' % (note, note_time))
            updateEvents()  # defined in export_events.py
            os.chdir('render')  # go back to render
            result = 'OK'

        if self.path == '/blog':
            # add note at specified time and refresh
            post = form.getvalue('post')
            if post is None:
                post = ''
            post_time = int(form.getvalue('time'))
            os.chdir(rootdir)  # pop out
            trev = rewindTime(post_time)
            open('logs/blog_%d.txt' % (post_time, ), 'w').write(post)
            updateEvents()  # defined in export_events.py
            os.chdir('render')  # go back to render
            result = 'OK'

        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write(result)
Beispiel #3
0
  def do_POST(self):
    form = cgi.FieldStorage(
      fp = self.rfile,
      headers = self.headers,
      environ = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type']})
    result = 'NOT_UNDERSTOOD'

    if self.path == '/refresh':
      # recompute jsons. We have to pop out to root from render directory
      # temporarily. It's a little ugly
      refresh_time = form.getvalue('time')
      os.chdir(rootdir) # pop out
      updateEvents() # defined in export_events.py
      os.chdir('render') # pop back to render directory
      result = 'OK'
      
    if self.path == '/addnote':
      # add note at specified time and refresh
      note = form.getvalue('note')
      note_time = form.getvalue('time')
      os.chdir(rootdir) # pop out
      os.system('echo %s | ./note.sh %s' % (note, note_time))
      updateEvents() # defined in export_events.py
      os.chdir('render') # go back to render
      result = 'OK'

    if self.path == '/blog':
      # add note at specified time and refresh
      post = form.getvalue('post')
      if post is None: post = ''
      post_time = int(form.getvalue('time'))
      os.chdir(rootdir) # pop out
      trev = rewindTime(post_time)
      open('logs/blog_%d.txt' % (post_time, ), 'w').write(post)
      updateEvents() # defined in export_events.py
      os.chdir('render') # go back to render
      result = 'OK'
    
    self.send_response(200)
    self.send_header('Content-type','text/html')
    self.end_headers()
    self.wfile.write(result)
Beispiel #4
0
    def do_POST(self):
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    "REQUEST_METHOD": "POST",
                                    "CONTENT_TYPE":
                                    self.headers["Content-Type"]
                                })
        result = "NOT_UNDERSTOOD"

        if self.path == "/refresh":
            # Recompute jsons.
            # We have to pop out to root from render directory temporarily. It's a little ugly
            refresh_time = int(form.getvalue("time"))
            if refresh_time > 0:
                printc(
                    "<green>Refreshing the view of uLogMe<white>, for the day '<magenta>{}<white>' ..."
                    .format(ppDay(refresh_time)))
                notify(
                    "Refreshing the view of <b>uLogMe</b>, for the day '<i>{}</i>' ..."
                    .format(ppDay(refresh_time)))
            else:
                printc(
                    "<green>Refreshing the view of uLogMe<white>, for the overview page ..."
                )
                notify(
                    "Refreshing the view of <b>uLogMe</b>, for the overview page ..."
                )
            # FIXME add a command line option to enable/disable the refresh notifications
            os.chdir(self.rootdir)  # pop out
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..",
                                  "render"))  # pop back to render directory
            result = "OK"

        if self.path == "/addnote":
            # add note at specified time and refresh
            note = form.getvalue("note")
            note_time = form.getvalue("time")
            printc(
                "<green>Adding a note in uLogMe<white>, with content '<blue>{}<white>' and time '<magenta>{!s}<white>' ..."
                .format(note, ppTime(int(note_time))))
            notify(
                "Adding a note in <b>uLogMe</b>, with content '<i>{}</i>' and time '<i>{!s}</i>' ..."
                .format(note, ppTime(int(note_time))),
                icon="note")
            os.chdir(self.rootdir)  # pop out
            writenote(note, note_time)
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..", "render"))  # go back to render
            result = "OK"

        if self.path == "/blog":
            # add note at specified time and refresh
            post = form.getvalue("post")
            if post is None:
                post = ""
            post_time = int(form.getvalue("time"))
            printc(
                "<green>Adding a blog post in uLogMe<white>, with content '<blue>{}<white>' and time '<magenta>{!s}<white>' ..."
                .format(post, ppDay(int(post_time))))
            notify(
                "Adding a blog post in <b>uLogMe</b>, with content '<i>{}</i>' and time '<i>{!s}</i>' ..."
                .format(post, ppDay(int(post_time))),
                icon="note")  # DEBUG
            os.chdir(self.rootdir)  # pop out
            trev = rewindTime(post_time)
            with open(
                    os.path.join("..", "logs", "blog_%d.txt" % (post_time, )),
                    "w") as f:
                f.write(post)
            updateEvents()  # defined in export_events.py
            os.chdir(os.path.join("..", "render"))  # go back to render
            result = "OK"

        # This part has to be done manually
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        try:  # We have a bytes, as in Python2
            self.wfile.write(result)
        except TypeError:  # We have a string, as in Python3
            self.wfile.write(bytes(result, "utf8"))
Beispiel #5
0
 def do_GET(self):
   # default behavior
   SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) 
   updateEvents() # defined in export_events.py