Пример #1
0
    def write_active_app(self):
        if self.current_app is not None:
            window_name = self.get_current_window_name()
            window_name = remove_non_ascii(window_name)

            if self.current_app == 'Google Chrome':
                window_name = self.get_current_chrome_tab()
                window_name = remove_non_ascii(window_name)
            elif self.current_app == 'Safari':
                window_name = self.get_current_safari_tab()
                window_name = remove_non_ascii(window_name)

            if window_name is None or len(window_name) == 0:
                name_to_log = self.current_app
            else:
                name_to_log = '%s :: %s' % (self.current_app, window_name)

            if name_to_log != self.last_app_logged:
                self.last_app_logged = name_to_log
                s = '%d %s' % (current_time(), name_to_log)

                if DEBUG_APP:
                    print s

                # substitute the rewound time to the window file pattern and write
                fname = self.options.active_window_file % (rewindTime(
                    current_time()), )

                with open(fname, 'a') as f:
                    f.write('%s\n' % s)
Пример #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(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)
Пример #3
0
  def write_active_app(self):
    if self.current_app is not None:
      window_name = self.get_current_window_name()
      window_name = remove_non_ascii(window_name)
      if self.current_app == 'Google Chrome':
        window_name = self.get_current_chrome_tab()
        window_name = remove_non_ascii(window_name)
      if window_name is None or len(window_name) == 0:
        name_to_log = self.current_app
      else:
        name_to_log = '%s :: %s' % (self.current_app, window_name)
      if name_to_log != self.last_app_logged:
        timestamp = current_time()

        if self.last_app_info != {}:
            # Set the end timestamp
            self.last_app_info['end'] = timestamp
            # Clean tag name
            if 'Google Chrome' in self.last_app_info["tag_name"]:
              print self.last_app_info
              self.last_app_info["tag_name"] = self.clean_window_name()
              print 'ran clean window'
              print self.last_app_info

            # Publish last app that was open
            publish_event(self.last_app_info)

        # Replace last app with current app
        self.last_app_info = {
            "user_id": USER_ID,
            "start": timestamp,
            "tag_name": self.current_app,
            "metadata": {
                "window": window_name
            }
        }


        self.last_app_logged = name_to_log
        s = '%d %s' % (timestamp, name_to_log)
        if DEBUG_APP:
          print s
        # substitute the rewound time to the window file pattern and write
        fname = self.options.active_window_file % (rewindTime(current_time()), )
        with open(fname, 'a') as f:
          f.write('%s\n' % s)
Пример #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 = 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)
Пример #5
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)
Пример #6
0
 def write_active_app(self):
   if self.current_app is not None:
     window_name = self.get_current_window_name()
     window_name = remove_non_ascii(window_name)
     if self.current_app == 'Google Chrome':
       window_name = self.get_current_chrome_tab()
       window_name = remove_non_ascii(window_name)
     if window_name is None or len(window_name) == 0:
       name_to_log = self.current_app
     else:
       name_to_log = '%s :: %s' % (self.current_app, window_name)
     if name_to_log != self.last_app_logged:
       self.last_app_logged = name_to_log
       s = '%d %s' % (current_time(), name_to_log)
       if DEBUG_APP:
         print s
       # substitute the rewound time to the window file pattern and write
       fname = self.options.active_window_file % (rewindTime(current_time()), )
       with open(fname, 'a') as f:
         f.write('%s\n' % s.encode('utf-8', 'ignore'))
Пример #7
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"))
Пример #8
0
        for entry in data:
            t = entry['time'].split(':')
            dt = datetime.datetime(year=date.year,
                                   month=date.month,
                                   day=date.day,
                                   hour=int(t[0]),
                                   minute=int(t[1]),
                                   second=int(t[2]))
            all_times.append((dt, entry['value']))

    all_times = sorted(all_times, key=lambda x: x[0])
    steps = {}

    for t, v in all_times:
        tt = int(t.strftime('%s'))
        rt = rewind7am.rewindTime(tt)
        if rt not in steps:
            steps[rt] = []
        steps[rt].append((tt, v))

    for vals in steps.values():
        print(sum([v[1] for v in vals]))

    ii = 0
    for k, vv in steps.items():
        with open(os.path.join(LOGDIR, 'steps_{}.txt'.format(k)), 'w') as f:
            if ii == 0 and len(vv) < 1440:
                ii += 1
                continue
            for tt, v in vv:
                f.write('{} {}\n'.format(tt, v))