maxbbraun / trump2cash

A stock trading bot powered by Trump tweets
https://trump2cash.biz
MIT License
6.25k stars 855 forks source link

Crash when trying to tweet with too many companies #43

Closed maxbbraun closed 7 years ago

maxbbraun commented 7 years ago
Traceback (most recent call last):
  File "/home/max_braun/trump2cash/twitter.py", line 219, in process_queue
    self.handle_data(logs, data)
  File "/home/max_braun/trump2cash/twitter.py", line 276, in handle_data
    self.callback(tweet)
  File "/home/max_braun/trump2cash/main.py", line 24, in twitter_callback
    twitter.tweet(companies, tweet)
  File "/home/max_braun/trump2cash/twitter.py", line 89, in tweet
    self.twitter_api.update_status(text)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/api.py", line 194, in update_status
    )(post_data=post_data, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 229, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
TweepError: [{u'message': u'Status is over 140 characters.', u'code': 186}]

Two recent tweets (838862131852369922, 838861512999649286) ran into this issue. Trading was not affected.

The plan is to pick a less verbose format for the tweet text to begin with, then truncate to 140 characters if it's still over.

maxbbraun commented 7 years ago

Tweet text example before:

ExxonMobil $XOM 👍 ExxonMobil (BlackRock) $BLK 👍 ExxonMobil (PNC Financial Services) $PNC 👍 ExxonMobil (State Street Corporation) $STT 👍 https://twitter.com/realDonaldTrump/status/838862131852369922

And after https://github.com/maxbbraun/trump2cash/commit/17c21ce44ae517210208850995cd1f21d18f302a:

ExxonMobil 👍 $XOM $BLK $PNC $STT https://twitter.com/realDonaldTrump/status/838862131852369922