Help with twitter bot [not Spark related]

Hi spark community! I have been having trouble with my twitter bot that tweets my pi’s cpu temp. I want my pi to tweet it’s cpu temp and it does but I also want it to send a new updated tweet every 300 seconds. I’ve tried to place the while True in different places but it all does the same thing. It tweets every 300 seconds but it tweets the same tweet and the twitter api doesn’t allow it. I want it to send a updated cpu temp every 300 seconds and it isn’t doing that. I have another project for my spark core which displays my tweets but I’m done with that project. Feel free to edit the code. This has been very frustrating to try and edit but it doesn’t do what I want. This does is going to be where my core is displaying the pi’s cpu temp so it is important to my spark project. The spark project was much easier.

#!/usr/bin/env python2.7  
    # tweet2.py by Alex Eames http://raspi.tv/?p=5941  
    import tweepy  
    import sys  
    import os  
    from datetime import datetime  
    from time import sleep
    while True:   
   		i = datetime.now()  
    degree = unichr(176)         # code for degree symbol  
      
    # Consumer keys and access tokens, used for OAuth  
    consumer_key = 'type in your consumer key here'  
    consumer_secret = 'type in your consumer secret here'  
    access_token = 'type in your access token here'  
    access_token_secret = 'type in your access token secret here'  
      
    # OAuth process, using the keys and tokens  
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)  
    auth.set_access_token(access_token, access_token_secret)  
       
    # Creation of the actual interface, using authentication  
    api = tweepy.API(auth)  
      
    if len(sys.argv) >= 2:        # use entered text as tweet  
        tweet_text = sys.argv[1]  
while True:
    else:                         # if no entered text, tweet the temp  
        now = i.strftime('%Y/%m/%d %H:%M:%S')  
        cmd = '/opt/vc/bin/vcgencmd measure_temp'  
        line = os.popen(cmd).readline().strip()  
        temp = line.split('=')[1].split("'")[0]  
        print now + ' Pi Processor Temperature is '+ temp + ' ' + degree +'C'  
        tweet_text = now + ' Pi Processor Temperature is '+ temp + ' ' + degree +'C'  
      
    if len(tweet_text) <= 140:  
        api.update_status(status=tweet_text)  
    else:  
        print "tweet not sent. Too long. 140 chars Max."  
sleep(60)

I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy

I don’t want to ruin the party, but this forum is meant for the Spark ecosystem. That’s not to say that there aren’t any people able to help, but you’re probably going to find better help on a forum dedicated to Rpi/python stuff. Also, if everyone is going to ask questions about non-Spark related items this whole forum will quickly become unmanageable and disorganised. It is with those interests in mind that I would kindly like to request that you keep non-Spark questions to a bare minimum in the future.

Having said that, I hope you’ll find the help you need. Best of luck!

2 Likes

This is part of my project that uses the two boards. The pi tweets it’s cpu temp and with the help of a bread board and a lcd display with a spark core. I can see what my pi’s cpu temp with my core. So I should only post about the part of the project that uses the core and not the pi. I thought I should post about the whole project. Sorry.

You can most definitely post about the project as a whole! But when it comes to troubleshooting, it’s more useful to break a project up into different ‘blocks’.
Displaying tweets via a Spark Core is a standalone project on its own, and so is tweeting a message from a Pi.
You don’t need the Spark in order to be able to post those temperatures to twitter. Nor do you need the Pi to be able to display tweets using your Spark. The Spark is merely a receiver in the Internet of Things configurations you’ve set up, whereas the Pi is the sender. Both can, and should, be treated separately.
If you were to ask how to set-up your Spark Core on a Raspberry forum, you’d probably get a few strange looks as well, since they have absolutely nothing to do with each other.
It’s like asking how to install a waterline, just so I can wash my car. To wash your car, you need water. To get water, you need the water line. The car however, does not care where you got the water from, just like the waterline doesn’t care where the water goes. They’re separate, independent systems, and should be treated as such. (pi = waterline, water = tweet, car = Spark)

If you’ve got your Core part of your project working, and your Pi part is the problem, then you’re more likely to find help on a forum that is specialized in Pi stuff, whereas you’ll find more info for the Spark here.

Thanks for understanding. I liked the analogy.

1 Like