Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python2 to Python3 porting. #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

avinashkanaujiya
Copy link

But their is a issue of 404 error with export_list.json. It isn't being generated and I think the problem is with, export_events.py file on line 53.
I didn't understand what is wrong.

Copy link

@danuker danuker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your conversion to Python 3. But since you touched the code, you now own it 😉

Please install a PEP 8 linter in your IDE or workflow (like flake8). You will find that code will become readable and consistent eventually (though you should read about and/or ignore warnings you think are misguided).

Also, I didn't like all the open().write() calls that were already in the code; the files are not closed. But I think this is outside the scope of this small change (which is why I didn't comment).

You should perhaps check out 2to3 which lets you automatically convert to Python 3.

Thanks again for the changes anyway; your code does the job!


print 'Serving ulogme, see it on http://localhost:' + `PORT`
print('Serving ulogme, see it on http://localhost:',str(PORT))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For it to be a link in the terminal you have to use + instead of ,:

print('Serving ulogme, see it on http://localhost:'+str(PORT))

or even better, with F-Strings (but they depend on Python 3.6):

print(f'Serving ulogme, see it on http://localhost:{PORT}'))

print 'error was:'
print e
except Exception as e:
print ('%s probably does not exist, setting empty events list.' % (fname, ))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use white space "Immediately before the open parenthesis that starts the argument list of a function call:":

print('%s probably does not exist, setting empty events list.' % (fname, ))

@danuker
Copy link

danuker commented Sep 11, 2020

I tried to fiddle around with the code, but I could not get it working even using Python 2.7.

Perhaps the server implementation changed, and is no longer responsive to os.chdir. Perhaps the SimpleHTTPRequestHandler inheritance is also different now.

This is why I hate inheritance - it is coupled with the implementation. I will try to fix it.

@danuker
Copy link

danuker commented Sep 11, 2020

Guess what is written in the README:

The user interface

  1. Important. As a one-time setup, copy over the example settings file to your own copy: $ cp render/render_settings_example.js render/render_settings.js to create your own render_settings.js settings file. In this file modify everything to your own preferences. Follow the provided example to specify title mappings: A raw window title comes in, and we match it against regular expressions to determine what type of activity it is. For example, the code would convert "Google Chrome - some cool website" into just "Google Chrome". Follow the provided example and read the comments for all settings in the file.
  2. Once that's set up, start the web server viewer: $ python ulogme_serve.py, and go to to the provided address) for example http://localhost:8123) in your browser. Hit the refresh button on top right every time you'd like to refresh the results based on most recently recorded activity
  3. If your data isn't loading, try to explicitly run python export_events.py and then hit refresh. This should only be an issue the very first time you run ulogme.
  1. Run this:
cp render/render_settings_example.js render/render_settings.js
2to3 -w export_events.py
  1. Remove the .decode('utf-8') and .encode('utf8') from export_events.py

  2. Replace self.wfile.write(result) with self.wfile.write(bytes(result, 'utf-8') in ulogme_serve.py

  3. Run this:

rm render/events_*.json render/export_list.json
python export_events.py

😆 It doesn't throw 404's anymore, and seems to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants