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

Hop 0.8.0 #66

Merged
merged 16 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ testtools==2.5.0
virtualenv==20.13.0
wheel==0.34.2
inquirer>=2.8.0
hop-client<=0.5.1
hop-client<=0.8.0
attrs~=21.4.0
docutils==0.17.1
myst-parser==0.16.1
Expand Down
3 changes: 2 additions & 1 deletion snews_pt/snews_pub.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am going to try all these new updates, as soon as I find some time. Thanks for upgrade!

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dateutil.parser import isoparse as fromisoformat
import os, click
from hop import Stream
from hop.models import JSONBlob
joesmolsky marked this conversation as resolved.
Show resolved Hide resolved
from . import snews_pt_utils
from .snews_format_checker import SnewsFormat
from .snews_pt_utils import prettyprint_dictionary
Expand Down Expand Up @@ -99,7 +100,7 @@ def send(self, messages):
messages = list(messages)
for message in messages:
message["sent_time"] = datetime.utcnow().isoformat()
self.stream.write(message)
self.stream.write(JSONBlob(message))
self.display_message(message)


Expand Down
74 changes: 52 additions & 22 deletions snews_pt/snews_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,67 @@ def save_message(message, outputfolder, return_file=False):
"""
file = make_file(outputfolder)
with open(file, 'w') as outfile:
json.dump(message, outfile, indent=4, sort_keys=True)
try:
json.dump(message, outfile, indent=4, sort_keys=True)
except TypeError as te:
json.dump(message.content, outfile, indent=4, sort_keys=True)
if return_file:
return file

def display(message):
""" Function to format output messages
"""
click.echo(click.style('ALERT MESSAGE'.center(65, '_'), bg='red', bold=True))
for k, v in message.items():
key_type = type(v)
if key_type == type(None):
v = 'None'

if key_type in [int, float, str]:
if k=='alert_type':
if v=='RETRACTION':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='red'))
elif v=='UPDATE':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='blue'))
try:
joesmolsky marked this conversation as resolved.
Show resolved Hide resolved
for k, v in message.items():
key_type = type(v)
if key_type == type(None):
v = 'None'

if key_type in [int, float, str]:
if k=='alert_type':
if v=='RETRACTION':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='red'))
elif v=='UPDATE':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='blue'))
else:
click.echo(f'{k:<20s}:{v:<45}')
else:
click.echo(f'{k:<20s}:{v:<45}')

elif key_type == list:
v = [str(item) for item in v]
items = '\t'.join(v)
if k == 'detector_names':
click.echo(f'{k:<20s}' + click.style(f':{items:<45}', bg='blue'))
else:
click.echo(f'{k:<20s}:{items:<45}')

except AttributeError as ae:
for k, v in message.content.items():
key_type = type(v)
if key_type == type(None):
v = 'None'

if key_type in [int, float, str]:
if k=='alert_type':
if v=='RETRACTION':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='red'))
elif v=='UPDATE':
click.echo(f'{k:<20s}' + click.style(f':{v:<45}', bg='blue'))
else:
click.echo(f'{k:<20s}:{v:<45}')
else:
click.echo(f'{k:<20s}:{v:<45}')
else:
click.echo(f'{k:<20s}:{v:<45}')

elif key_type == list:
v = [str(item) for item in v]
items = '\t'.join(v)
if k == 'detector_names':
click.echo(f'{k:<20s}' + click.style(f':{items:<45}', bg='blue'))
else:
click.echo(f'{k:<20s}:{items:<45}')

elif key_type == list:
v = [str(item) for item in v]
items = '\t'.join(v)
if k == 'detector_names':
click.echo(f'{k:<20s}' + click.style(f':{items:<45}', bg='blue'))
else:
click.echo(f'{k:<20s}:{items:<45}')

click.secho('_'.center(65, '_'), bg='bright_red')


Expand Down