Search

Creating a Twitter Bot to Bring my Analytics to the People

First - If you like stocks and have twitter, follow me @emrichesdotcom.



Second - I created a twitter bot to automatically display my illustrative analytics to the twitter community automatically. Basically, every time my code runs (i.e. pulling data from sec.gov and analyzing it accordingly) it creates 30+ graphical outputs. These updated graphics are updated on my website continuously. But now, my twitter bot takes an image and shares it with the twitter community. Best part, it is all automated; no time wasted on my part.


Twitter Bot python code is as follows:

#Twitter Bot

import tweepy

import virtualenv


API_KEY = "insert your key here"

API_KEY_SECRET = "insert your key secret here"

ACCESS_TOKEN = "insert your token here"

ACCESS_TOKEN_SECRET = "insert your token secret here"


#Test Credentials


# Authenticate to Twitter

auth = tweepy.OAuthHandler(API_KEY, API_KEY_SECRET)

auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)


api = tweepy.API(auth)


try:

api.verify_credentials()

print("Authentication OK")

except:

print("Error during authentication")


# Authenticate to Twitter


# Create API object

# Create API object

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)


import random

num1 = random.randint(1, "insert number of pre-made comments")

print(num1)


#api.update_status("Test tweet from Tweepy Python")

if num1 == 1:

media = api.media_upload("Large_Compare.png")

#Media is the image you want uploaded Tweet is the tweet verbiage you want to accompany the impage

tweet = "A look at $PLAN operations, balance sheet, and valuation...all in one chart for a relative perspective. www.emriches.com/anaplan #Investing #Anaplan"

post_result = api.update_status(status=tweet, media_ids=[media.media_id])


#Include more comments as needed; i usually have 30+ per stock I follow. Therefore, every time my code runs, it picks out one comment to display to twitter. With the inventory of pre-fabricated tweets, my content changes (i.e. rotates) every time my bot posts.




8 views0 comments

© 2020 by Emriches.com. 

  • Facebook Icon
  • Twitter Icon