Skip to content

Commit

Permalink
Merge branch 'release/0.3.7rc1'
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmaloney committed Jul 20, 2019
2 parents 3aae3e6 + 3df57ef commit d9d80c1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,16 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

### Release
### [0.3.7] - TBD

#### Fixed
- Upgrade to Mastodon.py 1.4.5
- Rudimentary support for polls (shows links to polls)
- Update colored minimum version to 1.3.93 (Fixes GPL license incompatibility)
- Support Pleroma FlakeIDs
- Minor fix for stream command being closed without receiving a toot getting a Nonetype for handle

### Release
### [0.3.6] - 2018-09-29

#### Added
- Updated to Mastodon 1.3.1 (No additional features yet)
- Updated to Mastodon.py 1.3.1 (No additional features yet)
- Added links command to show links in a toot and optionally open them in a browser
- Added puburl command to show the public URL of a toot

#### Fixed
- Upgrade to Mastodon 1.3.1 fixes searching for users issue noted in 0.3.5
- Upgrade to Mastodon.py 1.3.1 fixes searching for users issue noted in 0.3.5
- Spelling mistakes
- Added better error message for streaming support not supported on older mastodon instances

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
@@ -1,5 +1,5 @@
click>=6.7
Mastodon.py==1.3.1
colored>=1.3.5
Mastodon.py==1.4.5
colored>=1.3.93
humanize>=0.5.1
emoji>=0.4.5
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
setup(
name="tootstream",
version="0.3.6",
version="0.3.7",
python_requires=">=3",
install_requires=[line.strip() for line in open('requirements.txt')],

Expand Down
62 changes: 48 additions & 14 deletions src/tootstream/toot.py
Expand Up @@ -72,7 +72,6 @@ def __init__(self):
def to_local(self, global_id):
"""Returns the local ID for a global ID"""
try:
global_id = int(global_id) # In case a string gets passed
return self._map.index(global_id)
except ValueError:
self._map.append(global_id)
Expand Down Expand Up @@ -140,6 +139,13 @@ def get_content(toot):
return toot_parser.get_text()


def get_poll(toot):
poll = getattr(toot, 'poll', None)
if poll:
uri = toot['uri']
return " [poll]: {}".format(uri)


def get_userid(mastodon, rest):
# we got some user input. we need a userid (int).
# returns userid as int, -1 on error, or list of users if ambiguous.
Expand Down Expand Up @@ -205,15 +211,17 @@ def flaghandler_note(mastodon, rest):
kwargs = {'mention': True,
'favourite': True,
'reblog': True,
'follow': True}
'follow': True,
'poll': True}

flags = {'m': False,
'f': False,
'b': False,
'F': False}
'F': False,
'p': False}

# token-grabbing loop
# recognize `note -m -f -b -F` as well as `note -mfbF`
# recognize `note -m -f -b -F -p` as well as `note -mfbFp`
while rest.startswith('-'):
# get the next token
(args, _, rest) = rest.partition(' ')
Expand All @@ -228,6 +236,8 @@ def flaghandler_note(mastodon, rest):
kwargs['reblog'] = False
if 'F' in args:
kwargs['follow'] = False
if 'p' in args:
kwargs['poll'] = False

return (rest, kwargs)

Expand Down Expand Up @@ -514,6 +524,7 @@ def register_app(instance):
raises a Mastodon exception otherwise.
"""
return Mastodon.create_app( 'tootstream',
scopes=['read', 'write', 'follow'],
api_base_url="https://" + instance )


Expand All @@ -533,11 +544,11 @@ def login(instance, client_id, client_secret):
)

print("Click the link to authorize login.")
print(mastodon.auth_request_url())
print(mastodon.auth_request_url(scopes=['read', 'write', 'follow']))
print()
code = input("Enter the code you received >")

return mastodon.log_in(code = code)
return mastodon.log_in(code = code, scopes=['read', 'write', 'follow'])


def get_or_input_profile(config, profile, instance=None):
Expand Down Expand Up @@ -746,6 +757,9 @@ def printToot(toot):
for media in toot['media_attachments']:
out.append(stylize(" " + nsfw + " " + media.url, fg('green')))

if toot.get('poll'):
out.append(" [poll]") # if there's a poll then just show that it exists for now

print( '\n'.join(out) )
print()

Expand Down Expand Up @@ -1005,7 +1019,7 @@ def rep(mastodon, rest):
while posted is False:
try:
reply_toot = mastodon.status_post('%s %s' % (mentions, text),
in_reply_to_id=int(parent_id),
in_reply_to_id=parent_id,
**kwargs)
msg = " Replied with: " + get_content(reply_toot)
cprint(msg, fg('red'))
Expand Down Expand Up @@ -1320,11 +1334,14 @@ def say_error(*args, **kwargs):

try:
if rest == "home" or rest == "":
handle = mastodon.stream_user(toot_listener, run_async=True)
handle = mastodon.stream_user(toot_listener, run_async=True,
reconnect_async=True)
elif rest == "fed" or rest == "public":
handle = mastodon.stream_public(toot_listener, run_async=True)
handle = mastodon.stream_public(toot_listener, run_async=True,
reconnect_async=True)
elif rest == "local":
handle = mastodon.stream_local(toot_listener, run_async=True)
handle = mastodon.stream_local(toot_listener, run_async=True,
reconnect_async=True)
elif rest.startswith('list'):
# Remove list from the rest string
items = rest.split('list ')
Expand All @@ -1336,10 +1353,12 @@ def say_error(*args, **kwargs):
cprint("List {} is not found".format(items[-1]), fg('red'))
return

handle = mastodon.stream_list(item, toot_listener, run_async=True)
handle = mastodon.stream_list(item, toot_listener, run_async=True,
reconnect_async=True)
elif rest.startswith('#'):
tag = rest[1:]
handle = mastodon.stream_hashtag(tag, toot_listener, run_async=True)
handle = mastodon.stream_hashtag(tag, toot_listener, run_async=True,
reconnect_async=True)
else:
handle = None
print("Only 'home', 'fed', 'local', 'list', and '#hashtag' streams are supported.")
Expand Down Expand Up @@ -1373,7 +1392,11 @@ def say_error(*args, **kwargs):
command = command[0]
cmd_func = commands.get(command, say_error)
cmd_func(mastodon, rest_)
handle.close()
try:
handle.close()
except AttributeError:
handle.running = False
pass # Trap for handle not getting set if no toots were received while streaming
is_streaming = False
stream.__argstr__ = '<timeline>'
stream.__section__ = 'Timeline'
Expand Down Expand Up @@ -1442,18 +1465,29 @@ def note(mastodon, rest):
cprint(" favorited your status:", fg('yellow'))
print(" "+countsline + stylize(time, attr('dim')))
cprint(content, attr('dim'))

if getattr(note['status'], 'poll', None):
poll = get_poll(note['status'])
cprint(poll, attr('dim'))

# Boosts
elif note['type'] == 'reblog':
cprint(display_name + username + " boosted your status:", fg('yellow'))
cprint(get_content(note['status']), attr('dim'))
if getattr(note['status'], 'poll', None):
poll = get_poll(note['status'])
cprint(poll, attr('dim'))

# Follows
elif note['type'] == 'follow':
print(" ", end="")
cprint(display_name + username + " followed you!", fg('yellow'))

# Poll
elif note['type'] == 'poll':
cprint(get_content(note['status']), attr('dim'))
cprint(get_poll(note['status']), attr('dim'))


# blank line
print()
note.__argstr__ = '[<filter>]'
Expand Down

0 comments on commit d9d80c1

Please sign in to comment.