adds Mastodon features and testmode #2

Merged
bernd2k merged 10 commits from mastodon into master 2020-01-06 13:34:55 +00:00
Showing only changes of commit 9bcff4f4d7 - Show all commits

View file

@ -1,9 +1,3 @@
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
import json import json
import os import os
import time import time
@ -13,6 +7,16 @@ import tweepy
from mastodon import Mastodon from mastodon import Mastodon
import random import random
import time import time
testmode = True
if testmode != True:
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("Mode: operational")
else:
print("Mode: test")
def textselect(min, max): def textselect(min, max):
@ -58,20 +62,27 @@ state_b4 = 1
while True: while True:
if GPIO.input(12) == GPIO.HIGH: if testmode != True:
#print("button was pushed:") if GPIO.input(12) == GPIO.HIGH:
#print("button was pushed:")
state = 1 state = 1
if GPIO.input(12) == GPIO.LOW: if GPIO.input(12) == GPIO.LOW:
#print("button was not pushed:") #print("button was not pushed:")
state = 0 state = 0
else:
# just toggles the states for test mode!
if state == 0:
state = 1
else:
state = 0
time_now = time.time() time_now = time.time()
file_status_path = dir_path + os.sep + "status.json" file_status_path = dir_path + os.sep + "status.json"
if state == 1 and state_b4 == 0: if state == 1 and state_b4 == 0:
@ -86,20 +97,22 @@ while True:
time_opening = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S') time_opening = datetime.datetime.fromtimestamp(int(time_now)).strftime('%Y-%m-%d %H:%M:%S')
texts = data_status["opening_text"][number]["text"] texts = data_status["opening_text"][number]["text"]
if texts.get("twitter") != None: if TWITTER_ACCESS_KEY != "fill in your data!":
text = texts["twitter"] + " [OPEN:" + time_opening + "]" if texts.get("twitter") != None:
text = texts["twitter"] + " [OPEN:" + time_opening + "]"
else: else:
text = texts["universal"] + " [OPEN:" + time_opening + "]" text = texts["universal"] + " [OPEN:" + time_opening + "]"
print("twitter text:", text) print("twitter text:", text)
try: if testmode != True:
twitter_api.update_status(text) try:
# same text as before cannot be posted! twitter_api.update_status(text)
except: # same text as before cannot be posted!
print(time_now, "did not tweet opening status") except:
print(time_now, "did not tweet opening status")
@ -114,14 +127,15 @@ while True:
print("mastodon text:", text) print("mastodon text:", text)
try: if testmode != True:
mastodon = Mastodon( try:
access_token=MASTODON_ACCESS_TOKEN, mastodon = Mastodon(
api_base_url=MASTODON_API_BASE_URL access_token=MASTODON_ACCESS_TOKEN,
) api_base_url=MASTODON_API_BASE_URL
mastodon.toot(text) )
except: mastodon.toot(text)
print(time_now, "did not toot closing status", time_closing) except:
print(time_now, "did not toot closing status", time_closing)
@ -139,20 +153,22 @@ while True:
time_closing = datetime.datetime.fromtimestamp(int( time_now )).strftime('%Y-%m-%d %H:%M:%S') time_closing = datetime.datetime.fromtimestamp(int( time_now )).strftime('%Y-%m-%d %H:%M:%S')
texts = data_status["closing_text"][number]["text"] texts = data_status["closing_text"][number]["text"]
if texts.get("twitter") != None: if MASTODON_ACCESS_TOKEN != "fill in your data!":
text = texts["twitter"] + " [CLOSED:" + time_closing + "]" if texts.get("twitter") != None:
text = texts["twitter"] + " [CLOSED:" + time_closing + "]"
else: else:
text = texts["universal"] + " [CLOSED:" + time_closing + "]" text = texts["universal"] + " [CLOSED:" + time_closing + "]"
print("Twitter Text:", text) print("twitter text:", text)
try: if testmode != True:
twitter_api.update_status(text) try:
# same text as before cannot be posted! twitter_api.update_status(text)
except: # same text as before cannot be posted!
print(time_now, "did not tweet closing status") except:
print(time_now, "did not tweet closing status")
@ -166,14 +182,15 @@ while True:
print("mastodon text:", text) print("mastodon text:", text)
try: if testmode != True:
mastodon = Mastodon( try:
access_token=MASTODON_ACCESS_TOKEN, mastodon = Mastodon(
api_base_url=MASTODON_API_BASE_URL access_token=MASTODON_ACCESS_TOKEN,
) api_base_url=MASTODON_API_BASE_URL
mastodon.toot(text) )
except: mastodon.toot(text)
print(time_now, "did not toot closing status", time_closing) except:
print(time_now, "did not toot closing status", time_closing)
state_b4 = state state_b4 = state