Jump to content

Hi I have setup a twitter bot but I want to change the code to tweet the pi's cpu temp every 300 seconds but i tries to send the same tweet over and over. I want it to send different tweets every time. On each tweet the hour, minuet and second are included.
Here is the code. I am very new to this. Thanks for understanding. I know what is wrong. The while True: for the main loop is in the wrong place ad is sending the same value of tweet_text every 300 seconds.

#!/usr/bin/env python2.7
# tweet2.py by Alex Eames Tweeting System Information from the Raspberry Pi – part 3 Pi Twitter app series
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]

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'
while True:
if len(tweet_text) <= 140:
api.update_status(status=tweet_text)
else:
print "tweet not sent. Too long. 140 chars Max."
sleep(300)

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/
Share on other sites

Link to post
Share on other sites

I don't think twitter bots are against coc. My friend made one that would take our university's tweet and convert the text to make it should like a 5 year old. Or something along the lines. It was really funny!

That said, it would have been nice if you stuck it in a code text box.

CM Storm Switch Tester MOD (In-Progress) - http://linustechtips.com/main/topic/409147-cm-storm-switch-tester-macro-mod/


       Ammo Can Speaker 02 (Completed) - http://linustechtips.com/main/topic/283826-ammo-can-speakers-02/       A/B Switch V 0.5 (Completed) - http://linustechtips.com/main/topic/362417-ab-switch-v0


     Build 01 - The Life of a Prodigy -  http://linustechtips.com/main/topic/13103-build-01-the-life-of-a-prodigy/             Build 02 - Silent Server 3000 - http://linustechtips.com/main/topic/116670-build-02-silent-server-3000/

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168023
Share on other sites

Link to post
Share on other sites

this is against coc

you cant just post it to here thinking we'll help you with such stuff

@IMPERIUS How is this against CoC? It's not illegal :P

 

@rpiswag what is not working? What is it doing at the moment? Also, use the code posting function (8th button from the left on the lower post function bar)

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168036
Share on other sites

Link to post
Share on other sites

How is it against CoC?

 

@IMPERIUS

 

Its a spam bot? Ppl don't want spam? I haven't read the coc but its kinda logical that lmg wouldn't want to support such things

 

@NeatSquidYT

@Minibois

Longboarders/ skaters message me!

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168037
Share on other sites

Link to post
Share on other sites

There is nothing wrong with a twitter bot as long as you are not spamming out viruses and malware and those Saudi prince stories.

CM Storm Switch Tester MOD (In-Progress) - http://linustechtips.com/main/topic/409147-cm-storm-switch-tester-macro-mod/


       Ammo Can Speaker 02 (Completed) - http://linustechtips.com/main/topic/283826-ammo-can-speakers-02/       A/B Switch V 0.5 (Completed) - http://linustechtips.com/main/topic/362417-ab-switch-v0


     Build 01 - The Life of a Prodigy -  http://linustechtips.com/main/topic/13103-build-01-the-life-of-a-prodigy/             Build 02 - Silent Server 3000 - http://linustechtips.com/main/topic/116670-build-02-silent-server-3000/

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168046
Share on other sites

Link to post
Share on other sites

@IMPERIUS

 

Maybe if you read the post, it isn't spamming PEOPLE. It's a handy tool so that the OP can check his RPi temperature on his Twitter feed. Nothing immoral at all about that.

 

Oh, I thought that was a spam bot. Sorry :P

Longboarders/ skaters message me!

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168051
Share on other sites

Link to post
Share on other sites

Its a spam bot? Ppl don't want spam? I haven't read the coc but its kinda logical that lmg wouldn't want to support such things

 

@NeatSquidYT

@Minibois

@IMPERIUS it's a bot that posts a Twitter message every 3 minutes or something. Not directed to anyone, so nobody gets a notification.

It's not spamming ANYONE and Twitter doesn't specifically say it isn't allowed.

 

Please don't pull out the "Against COC"-card everytime you don't read a full topic  :P

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168058
Share on other sites

Link to post
Share on other sites

Sorry if I was not specific. The pi tweets but when it tries to tweet another 300 seconds latter it sends the same thing. I want it so tweet a different time and cpu temp. It currently tweets the time along with with cpu temp of the pi. The problem from my first post is the while True: for the main loop is in the wrong place and is sending the same value of tweet_text every 300 seconds.

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168119
Share on other sites

Link to post
Share on other sites

#!/usr/bin/env python2.7# tweet2.py by Alex Eames http://raspi.tv/?p=5941import tweepyimport sysimport osfrom datetime import datetime i = datetime.now()degree = unichr(176)         # code for degree symbol# Consumer keys and access tokens, used for OAuthconsumer_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 tokensauth = tweepy.OAuthHandler(consumer_key, consumer_secret)auth.set_access_token(access_token, access_token_secret) # Creation of the actual interface, using authenticationapi = tweepy.API(auth)if len(sys.argv) >= 2:        # use entered text as tweet    tweet_text = sys.argv[1]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."

You used the wrong code, use this instead and use a cronjob to execute it after you desired interval. while true is just nasty.

 

Edit: More info on cronjobs http://www.pantz.org/software/cron/croninfo.html

Edited by mr_greenguy

G5 casemod is done :D!

i5 2500K with Scythe Mugen 2 Rev. B | Asrock P67 Extreme4 Gen3 | 8GB @1600 | Club3D HD 7950 royalKing | Corsair Carbide 500R Black | Samsung 830 SSD 128GB + 2TB HDD | XFX ProSeries 750W XXX | dell u2312hm 

 

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4168368
Share on other sites

Link to post
Share on other sites

Its a spam bot? Ppl don't want spam? I haven't read the coc but its kinda logical that lmg wouldn't want to support such things

 

@NeatSquidYT

@Minibois

@IMPERIUS thank you for taking the time to use this forum. now go read the COC before you get yourself in a world of hate. 

CM Storm Switch Tester MOD (In-Progress) - http://linustechtips.com/main/topic/409147-cm-storm-switch-tester-macro-mod/


       Ammo Can Speaker 02 (Completed) - http://linustechtips.com/main/topic/283826-ammo-can-speakers-02/       A/B Switch V 0.5 (Completed) - http://linustechtips.com/main/topic/362417-ab-switch-v0


     Build 01 - The Life of a Prodigy -  http://linustechtips.com/main/topic/13103-build-01-the-life-of-a-prodigy/             Build 02 - Silent Server 3000 - http://linustechtips.com/main/topic/116670-build-02-silent-server-3000/

Link to comment
https://linustechtips.com/topic/306788-help-with-my-twitter-bot/#findComment-4170529
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×