adds Mastodon features and testmode #2
1 changed files with 24 additions and 27 deletions
|
@ -7,7 +7,7 @@ import tweepy
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
testmode = True
|
testmode = False
|
||||||
if testmode != True:
|
if testmode != True:
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
|
@ -28,6 +28,25 @@ def textselect(min, max):
|
||||||
return random.randint(min, max)
|
return random.randint(min, max)
|
||||||
|
|
||||||
|
|
||||||
|
def send_tweet(twitter_api, text, time_now, status):
|
||||||
|
try:
|
||||||
|
twitter_api.update_status(text)
|
||||||
|
# same text as before cannot be posted!
|
||||||
|
except:
|
||||||
|
print(time_now, "did not tweet", status, "status")
|
||||||
|
|
||||||
|
|
||||||
|
def send_toot(MASTODON_ACCESS_TOKEN, MASTODON_API_BASE_URL, text, time_now, status):
|
||||||
|
try:
|
||||||
|
mastodon = Mastodon(
|
||||||
|
access_token=MASTODON_ACCESS_TOKEN,
|
||||||
|
api_base_url=MASTODON_API_BASE_URL
|
||||||
|
)
|
||||||
|
mastodon.toot(text)
|
||||||
|
except:
|
||||||
|
print(time_now, "did not toot", status," status")
|
||||||
|
|
||||||
|
|
||||||
path = os.path.abspath(__file__)
|
path = os.path.abspath(__file__)
|
||||||
dir_path = os.path.dirname(path)
|
dir_path = os.path.dirname(path)
|
||||||
print("dir path is", dir_path)
|
print("dir path is", dir_path)
|
||||||
|
@ -108,11 +127,7 @@ while True:
|
||||||
print("twitter text:", text)
|
print("twitter text:", text)
|
||||||
|
|
||||||
if testmode != True:
|
if testmode != True:
|
||||||
try:
|
send_tweet(twitter_api, text, time_now, "opening")
|
||||||
twitter_api.update_status(text)
|
|
||||||
# same text as before cannot be posted!
|
|
||||||
except:
|
|
||||||
print(time_now, "did not tweet opening status")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,14 +143,7 @@ while True:
|
||||||
print("mastodon text:", text)
|
print("mastodon text:", text)
|
||||||
|
|
||||||
if testmode != True:
|
if testmode != True:
|
||||||
try:
|
send_toot(MASTODON_ACCESS_TOKEN, MASTODON_API_BASE_URL, text, time_now, "opening")
|
||||||
mastodon = Mastodon(
|
|
||||||
access_token=MASTODON_ACCESS_TOKEN,
|
|
||||||
api_base_url=MASTODON_API_BASE_URL
|
|
||||||
)
|
|
||||||
mastodon.toot(text)
|
|
||||||
except:
|
|
||||||
print(time_now, "did not toot closing status", time_closing)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,11 +172,7 @@ while True:
|
||||||
print("twitter text:", text)
|
print("twitter text:", text)
|
||||||
|
|
||||||
if testmode != True:
|
if testmode != True:
|
||||||
try:
|
send_tweet(twitter_api, text, time_now, "closing")
|
||||||
twitter_api.update_status(text)
|
|
||||||
# same text as before cannot be posted!
|
|
||||||
except:
|
|
||||||
print(time_now, "did not tweet closing status")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,14 +187,7 @@ while True:
|
||||||
print("mastodon text:", text)
|
print("mastodon text:", text)
|
||||||
|
|
||||||
if testmode != True:
|
if testmode != True:
|
||||||
try:
|
send_toot(MASTODON_ACCESS_TOKEN, MASTODON_API_BASE_URL, text, time_now, "closing")
|
||||||
mastodon = Mastodon(
|
|
||||||
access_token=MASTODON_ACCESS_TOKEN,
|
|
||||||
api_base_url=MASTODON_API_BASE_URL
|
|
||||||
)
|
|
||||||
mastodon.toot(text)
|
|
||||||
except:
|
|
||||||
print(time_now, "did not toot closing status", time_closing)
|
|
||||||
|
|
||||||
|
|
||||||
state_b4 = state
|
state_b4 = state
|
||||||
|
|
Reference in a new issue