From f5ce63493f1014cd99d8283776de349bf8145815 Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Wed, 1 Apr 2020 20:30:14 -0300 Subject: [PATCH] Make twitter post optional --- install.sh | 14 +++++++++++++- post.py | 9 +++++---- receive.sh | 16 +++++++++------- receive_meteor.sh | 11 +++++++---- templates/tweepy.conf | 4 ++++ 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 templates/tweepy.conf diff --git a/install.sh b/install.sh index 7ea7c08..856a881 100755 --- a/install.sh +++ b/install.sh @@ -116,6 +116,13 @@ else log_done "$HOME/.wxtoimgrc installed" fi +if [ -e "$HOME/.tweepy.conf" ]; then + log_done "$HOME/.tweepy.conf already exists" +else + cp "templates/tweepy.conf" "$HOME/.tweepy.conf" + log_done "$HOME/.tweepy.conf installed" +fi + ### Install meteor_demod if [ -e /usr/bin/meteor_demod ]; then log_done "meteor_demod was already installed" @@ -179,7 +186,7 @@ sudo mount -a set -e sudo chmod 777 /var/ramfs -success "Install (almost) done! Let's do some configuration" +success "Install (almost) done!" echo " It's time to configure your ground station You'll be asked for your latitude and longitude @@ -199,3 +206,8 @@ sed -i -e "s/change_latitude/${lat}/g;s/change_longitude/${lon}/g" "sun.py" success "Install done! Double check your $HOME/.noaa.conf settings" + +echo " + If you want to post your images to Twitter, please setup + your Twitter credentials on $HOME/.tweepy.conf +" diff --git a/post.py b/post.py index cfd2bdc..4252064 100755 --- a/post.py +++ b/post.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os import sys import tweepy -CONSUMER_KEY = '' -CONSUMER_SECRET = '' -ACCESS_TOKEN_KEY = '' -ACCESS_TOKEN_SECRET = '' +CONSUMER_KEY = os.environ['CONSUMER_KEY'] +CONSUMER_SECRET = os.environ['CONSUMER_SECRET'] +ACCESS_TOKEN_KEY = os.environ['ACCESS_TOKEN_KEY'] +ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET'] auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET) diff --git a/receive.sh b/receive.sh index 36879a8..a2529b4 100755 --- a/receive.sh +++ b/receive.sh @@ -2,8 +2,9 @@ ## import common lib -. ~/.noaa.conf -. "${NOAA_HOME}"/common.sh +. "$HOME/.noaa.conf" +. "$HOME/.tweepy.conf" +. "$NOAA_HOME/common.sh" ## pass start timestamp and sun elevation @@ -41,11 +42,12 @@ for i in $ENHANCEMENTS; do /usr/local/bin/wxtoimg -o -m "${NOAA_HOME}/map/${3}-map.png" -e "$i" "${NOAA_AUDIO}/audio/${3}.wav" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-$i.jpg" /usr/bin/convert -quality 90 -format jpg "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-$i.jpg" -undercolor black -fill yellow -pointsize 18 -annotate +20+20 "${1} $i ${START_DATE}" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-$i.jpg" done - -if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then - python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE}" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MSA-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-HVC-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-HVCT-precip.jpg" -else - python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE}" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR.jpg" +if [ -n "$CONSUMER_KEY" ]; then + if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then + python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE}" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MSA-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-HVC-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-HVCT-precip.jpg" + else + python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE}" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/$3-MCIR.jpg" + fi fi rm "${NOAA_AUDIO}/audio/${3}.wav" diff --git a/receive_meteor.sh b/receive_meteor.sh index 35b2e43..63d66ef 100755 --- a/receive_meteor.sh +++ b/receive_meteor.sh @@ -1,8 +1,9 @@ #!/bin/bash ## import common lib -. ~/.noaa.conf -. "${NOAA_HOME}"/common.sh +. "$HOME/.noaa.conf" +. "$HOME/.tweepy.conf" +. "$NOAA_HOME/common.sh" ## pass start timestamp and sun elevation PASS_START=$(expr "$5" + 90) @@ -53,8 +54,10 @@ if [ -f "${METEOR_OUTPUT}/${3}.dec" ]; then python3 "${NOAA_HOME}/rectify.py" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-122.jpg" rm "${METEOR_OUTPUT}/${3}-122.bmp" rm "${METEOR_OUTPUT}/${3}.bmp" - log "Posting to Twitter" "INFO" - python3 "${NOAA_HOME}/post.py" "$1 EXPERIMENTAL ${START_DATE} ResoluciĆ³n completa: http://weather.reyni.co/image/${FOLDER_DATE}/${3}-122-rectified.jpg" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-122-rectified.jpg" + if [ -n "$CONSUMER_KEY" ]; then + log "Posting to Twitter" "INFO" + python3 "${NOAA_HOME}/post.py" "$1 EXPERIMENTAL ${START_DATE} ResoluciĆ³n completa: http://weather.reyni.co/image/${FOLDER_DATE}/${3}-122-rectified.jpg" "$7" "${NOAA_OUTPUT}/image/${FOLDER_DATE}/${3}-122-rectified.jpg" + fi else log "Decoding failed, either a bad pass/low SNR or a software problem" "ERROR" fi diff --git a/templates/tweepy.conf b/templates/tweepy.conf new file mode 100644 index 0000000..9ee1606 --- /dev/null +++ b/templates/tweepy.conf @@ -0,0 +1,4 @@ +export CONSUMER_KEY="" +export CONSUMER_SECRET="" +export ACCESS_TOKEN_KEY="" +export ACCESS_TOKEN_SECRET=""