In [22]:
%cd ~/twitter-bots-smw-2016/
import warnings
warnings.filterwarnings('ignore',message='empty\sdatabase')


/Users/nickmacri/twitter-bots-smw-2016

In [25]:
import json
import random

# Kanye bot's library classes
from library import TwitterBot, MarkovBabbler, TwitterListener

# Kanye bot's class instances
from kanye_bot import get_kanye_babbler,get_listener,get_smw_seed_generators,generate_text
            
kanye = TwitterBot('production')
kanye.generate_text = generate_text
smw_listener = get_listener()

# load text data sets
f = open('data/smw/talks.ldjson','rb')
talks = [json.loads(l) for l in f.readlines()]
smw_program_text = " ".join([t['name']+" "+t['description'] for t in talks])
smw_program_text = smw_program_text + "\n".join([l for l in f.readlines()])
f.close()
smw_tweet_text_all = smw_listener.get_recent_text(1000)
smw_tweet_text_recent = smw_listener.get_recent_text(25)
f = open('data/kanye/quotes.txt','rb')
yeezy_text = "\n".join([l for l in f.readlines()])
f.close()

# make markov babblers
kanye_babbler = MarkovBabbler(yeezy_text)
smw_program_babbler = MarkovBabbler(smw_program_text)
smw_all_tweets_babbler = MarkovBabbler(smw_tweet_text_all)
smw_recent_tweets_babbler = MarkovBabbler(smw_tweet_text_recent)

def random_seed_generator():
    babbler = random.choice([smw_program_babbler,
                             smw_program_babbler,
                             smw_recent_tweets_babbler])
    return babbler.generate_seed()


WARNING:root:Database file corrupt or not found, using empty database
WARNING:root:Database file corrupt or not found, using empty database
WARNING:root:Database file corrupt or not found, using empty database
WARNING:root:Database file corrupt or not found, using empty database

In [31]:
random_seed_generator()


Text Candidate rejected for length <15
Text Candidate rejected for length > 140: Youll turn your next event into social media FOR THEIR OWN biz goals, as well as have an action plan to maximize social media traffic for e-commerce companies
Text Candidate rejected for length > 140: Building Brand Love and Changing Behavior Social media has the power to affect change and communicate our identity hasnt changed much over time
Text Candidate rejected for length > 140: But what if they loved your brand and regularly talked about you with their own social networks revolving around your brand and tech partners
Text Candidate rejected for length > 140: Data Can Make Content Smarter and More Social, presented by MTV When MTV first began researching post-Millennials, none of the Dark: How to Measure Dark Social You are failing to recognize 50% of the discussion will be Toby Daniels, founder and Shareablee CEO, Tania Yuki
Out[31]:
u'While going through the'

In [64]:
kanye_babbler.generate()


Text Candidate rejected for length > 140: she said, you know coming out and being forced to work every day trying to get this BMW, this Benz, to get this BMW, this Benz, to get mark to support me
Text Candidate rejected for length <15
Out[64]:
'one guy that will level, that will level, that will be the girl verson of bruh'

Question from @getmorevits


In [65]:
dms = kanye._api_client.GetDirectMessages()
dms


---------------------------------------------------------------------------
TwitterError                              Traceback (most recent call last)
<ipython-input-65-3898b917e519> in <module>()
----> 1 dms = kanye._api_client.GetDirectMessages()
      2 dms

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in GetDirectMessages(self, since_id, max_id, count, include_entities, skip_status)
   1855 
   1856     json = self._RequestUrl(url, 'GET', data=parameters)
-> 1857     data = self._ParseAndCheckTwitter(json.content)
   1858 
   1859     return [DirectMessage.NewFromJsonDict(x) for x in data]

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in _ParseAndCheckTwitter(self, json)
   3528     try:
   3529       data = simplejson.loads(json)
-> 3530       self._CheckForTwitterError(data)
   3531     except ValueError:
   3532       if "<title>Twitter / Over capacity</title>" in json:

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in _CheckForTwitterError(self, data)
   3555       raise TwitterError(data['error'])
   3556     if 'errors' in data:
-> 3557       raise TwitterError(data['errors'])
   3558 
   3559   def _RequestUrl(self, url, verb, data=None):

TwitterError: [{u'message': u'This application is not allowed to access or delete your direct messages.', u'code': 93}]

In [66]:
kanye._api_client.PostDirectMessage("Hi there",screen_name="getmorevits")


---------------------------------------------------------------------------
TwitterError                              Traceback (most recent call last)
<ipython-input-66-7651640a3f53> in <module>()
----> 1 kanye._api_client.PostDirectMessage("Hi there",screen_name="getmorevits")

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in PostDirectMessage(self, text, user_id, screen_name)
   1950 
   1951     json = self._RequestUrl(url, 'POST', data=data)
-> 1952     data = self._ParseAndCheckTwitter(json.content)
   1953 
   1954     return DirectMessage.NewFromJsonDict(data)

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in _ParseAndCheckTwitter(self, json)
   3528     try:
   3529       data = simplejson.loads(json)
-> 3530       self._CheckForTwitterError(data)
   3531     except ValueError:
   3532       if "<title>Twitter / Over capacity</title>" in json:

/Users/nickmacri/twitter-bots-smw-2016/venv/lib/python2.7/site-packages/twitter/api.pyc in _CheckForTwitterError(self, data)
   3555       raise TwitterError(data['error'])
   3556     if 'errors' in data:
-> 3557       raise TwitterError(data['errors'])
   3558 
   3559   def _RequestUrl(self, url, verb, data=None):

TwitterError: [{u'message': u'You cannot send messages to users who are not following you.', u'code': 150}]

In [77]:
kanye_babbler.generate(seed="@getmorevits Hi there ")


Text Candidate rejected for length > 140: @getmorevits Hi there could be completely quiet, because I believe that Season 1 presentation streamed to theaters in the lab with ian connor by the teachers, and I have answers, Im just sitting like Whoa, ok
Text Candidate rejected for length > 140: @getmorevits Hi there might be some others, there are people who work under the concept of time, time with your family, immediate or extended
Out[77]:
'@getmorevits Hi there might be thinking right now, Did he smoke something before he came out here and of course'

In [78]:
kanye.tweet('@getmorevits Hi there might be thinking right now, Did he smoke something before he came out here and of course')


Out[78]:
<twitter.status.Status at 0x10c42e7d0>