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

python3 #5

Open
wants to merge 1 commit 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
10 changes: 6 additions & 4 deletions get_message
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/python

from __future__ import print_function
import hesiod
import os
import select
import socket
import sys
import six
from optparse import OptionParser

MESSAGE_VERS = 'GMS:0'
Expand All @@ -25,7 +27,7 @@ def parse(msg):
"""Parse a gms message, returning a version, timestamp, text tuple
if successful, and an Exception otherwise."""
try:
header, text = msg.split('\n', 1)
header, text = six.ensure_str(msg).split('\n', 1)
version, timestamp = header.split(' ', 1)
if version != MESSAGE_VERS:
raise Exception('Incompatible version of GMS [%s] found' % (version,))
Expand Down Expand Up @@ -59,7 +61,7 @@ def write_message_times(timestamp):
def fetch_message():
"""Connect to the globalmessage server, and read a message."""
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.sendto('%s 0\n' % (MESSAGE_VERS,), (get_server(), GMS_PORT))
server.sendto(six.ensure_binary('%s 0\n' % (MESSAGE_VERS,)), (get_server(), GMS_PORT))
message = None
readable, _, _ = select.select([server], [], [], MESSAGE_TIMEOUT)
for i in readable:
Expand Down Expand Up @@ -100,15 +102,15 @@ def main():
options, args = parser.parse_args(
[old_args.get(x, x) for x in sys.argv[1:]])
if options.zephyr:
print >>sys.stderr, "get_message: The -z/-zephyr option is deprecated."
print("get_message: The -z/-zephyr option is deprecated.", file=sys.stderr)
version, timestamp, content = get_message()
if options.new and has_seen(timestamp):
# This is an already-seen message, and new-only was requested.
sys.exit(0)
if not options.login:
# Update the timestamp so we know this message has been seen
write_message_times(timestamp)
print content
print(content)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from distutils.core import setup

setup(name='get_message',
version='10.1.1',
version='10.2',
description='Athena utility for getting the global message of the day',
author='Alexander Chernyakhovsky',
scripts=['get_message']
Expand Down