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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions export_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def loadEvents(fname):
stamp = int(w[:ix])
str = w[ix+1:]
events.append({'t':stamp, 's':str})
except Exception, e:
print '%s probably does not exist, setting empty events list.' % (fname, )
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, ))

print ('error was:')
print (e)
events = []
return events

Expand Down Expand Up @@ -87,7 +87,7 @@ def updateEvents():
e4mod = mtime(e4f)
if e1mod > tmod or e2mod > tmod or e3mod > tmod or e4mod > tmod:
dowrite = True # better update!
print 'a log file has changed, so will update %s' % (fwrite, )
print ('a log file has changed, so will update %s' % (fwrite, ))
else:
# output file doesnt exist, so write.
dowrite = True
Expand All @@ -105,11 +105,11 @@ def updateEvents():

eout = {'window_events': e1, 'keyfreq_events': e2, 'notes_events': e3, 'blog': e4}
open(fwrite, 'w').write(json.dumps(eout))
print 'wrote ' + fwrite
print ('wrote ' + fwrite)

fwrite = os.path.join(RENDER_ROOT, 'export_list.json')
open(fwrite, 'w').write(json.dumps(out_list).encode('utf8'))
print 'wrote ' + fwrite
print ('wrote ' + fwrite)

# invoked as script
if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions rewind7am.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def rewindTime(t):
if __name__ == '__main__':
if len(sys.argv) <= 1:
# use right now
print rewindTime(int(time.time()))
print (rewindTime(int(time.time())))
else:
print rewindTime(int(sys.argv[1]))
print (rewindTime(int(sys.argv[1])))
12 changes: 6 additions & 6 deletions ulogme_serve.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SocketServer
import SimpleHTTPServer
import socketserver
import http.server
import sys
import cgi
import os
Expand All @@ -19,10 +19,10 @@
os.chdir('render')

# Custom handler
class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class CustomHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
# default behavior
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
http.server.SimpleHTTPRequestHandler.do_GET(self)

def do_POST(self):
form = cgi.FieldStorage(
Expand Down Expand Up @@ -67,8 +67,8 @@ def do_POST(self):
self.end_headers()
self.wfile.write(result)

httpd = SocketServer.ThreadingTCPServer((IP, PORT), CustomHandler)
httpd = socketserver.ThreadingTCPServer((IP, PORT), CustomHandler)

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}'))

httpd.serve_forever()