Skip to content

Commit

Permalink
python3
Browse files Browse the repository at this point in the history
  • Loading branch information
miriam-rittenberg committed Aug 23, 2020
1 parent e4a6814 commit 32fed58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 32fed58

Please sign in to comment.