def send(subject, body, signature="<br><br>Thanks,<br>Raspberry Pi", to=secureData.variable("email")): # Parse body += unquote(signature) message = MIMEMultipart() message["Subject"] = unquote(subject) message["From"] = "Raspberry Pi <" + username + ">" message["To"] = secureData.variable("email") message.attach(MIMEText(unquote(body), "html")) # Send Email context = ssl.create_default_context() with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: server.login(username, password) server.sendmail(message["From"], message["To"], message.as_string()) print("Sent Email")
def renewAccessToken(): params = (('client_id', client_id), ('client_secret', client_secret), ('refresh_token', secureData.variable("NestRefreshToken")), ('grant_type', 'refresh_token')) response = requests.post('https://www.googleapis.com/oauth2/v4/token', params=params) response_json = response.json() print(response.json()) access_token = response_json['token_type'] + ' ' + response_json[ 'access_token'] print('Access token: ' + access_token) secureData.write("NestAccessToken", access_token)
# scripts with the need to escape quotation characters. import smtplib from urllib.parse import unquote import ssl import sys from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart sys.path.insert(0, '/home/pi/Git/SecureData') import secureData # Parameters port = 465 smtp_server = "smtp.gmail.com" username = secureData.variable("email_pi") password = secureData.variable("email_pi_pw") def send(subject, body, signature="<br><br>Thanks,<br>Raspberry Pi", to=secureData.variable("email")): # Parse body += unquote(signature) message = MIMEMultipart() message["Subject"] = unquote(subject) message["From"] = "Raspberry Pi <" + username + ">" message["To"] = secureData.variable("email") message.attach(MIMEText(unquote(body), "html"))
import os, sys, socket currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) import secureData, mail s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) myIP = s.getsockname()[0] s.close() hostname = "192.168.1.123" if myIP == "192.168.1.123": hostname = "192.168.1.124" response = os.system("ping -c 1 " + hostname) if response != 0: email = secureData.variable("email") message = "Your server at " + hostname + " is down." mail.send(hostname + " is down", message)
import json import os import sys from requests import get currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) import secureData, mail currentIP = secureData.variable("currentIP") email = secureData.variable("email") print("Updating IP Address, " + email) ip = get('https://api.ipify.org?format=json').text discoveredIP = json.loads(ip)["ip"] print("Found " + discoveredIP + ", currently " + currentIP + ".") # IP was updated if (currentIP == discoveredIP): print("No change.") else: print("New IP! Updating and sending email.") secureData.write("currentIP", discoveredIP) # Replace OVPN file with new IP and email it newLine = "remote " + discoveredIP + " 1194" vpnFile = secureData.file("tyler.cloud.ovpn")
import secureData # Use only to log in manually # url = 'https://nestservices.google.com/partnerconnections/'+project_id+'/auth?redirect_uri='+redirect_uri+'&access_type=offline&prompt=consent&client_id='+client_id+'&response_type=code&scope=https://www.googleapis.com/auth/sdm.service' # print("Go to this URL to log in:") # print(url) # Constants project_id = secureData.array("NestIDs")[0] client_id = secureData.array("NestIDs")[1] client_secret = secureData.array("NestIDs")[2] code = secureData.array("NestIDs")[3] redirect_uri = 'https://www.tyler.cloud' # Access token- do we need to refresh? access_token = secureData.variable("NestAccessToken") # Get new Access Token by Passing the Refresh Token def renewAccessToken(): params = (('client_id', client_id), ('client_secret', client_secret), ('refresh_token', secureData.variable("NestRefreshToken")), ('grant_type', 'refresh_token')) response = requests.post('https://www.googleapis.com/oauth2/v4/token', params=params) response_json = response.json() print(response.json())
return utc_datetime + offset def shiftLocation(location): if(random.randrange(2) == 1): return d(location) + d(random.randrange(10000000)/100000000) else: return d(location) - d(random.randrange(10000000)/100000000) def getBikeLink(): return f"https://www.google.com/maps/dir//{shiftLocation(lat)},{shiftLocation(lon)}" def convertTemperature(temp): return round((temp - 273.15) * 9/5 + 32) # context variables plantyStatus = secureData.variable("plantyStatus") now = datetime.datetime.now() if(int(secureData.variable("walkAlertSent")) < (time.time() - 43200) and now.hour >= 10): secureData.log("Walk Alert Checked") # Call API url_request = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={secureData.variable('weatherAPIKey')}" response = requests.get(url_request).json() temperature = convertTemperature(response["current"]["temp"]) low = convertTemperature(response["daily"][1]["temp"]["min"]) high = convertTemperature(response["daily"][0]["temp"]["max"]) wind = response["current"]["wind_speed"] sunset = response["daily"][0]["sunset"] timeToSunset = (sunset - time.time()) / 3600
from spotipy.oauth2 import SpotifyClientCredentials import os from os import path import datetime import sys import subprocess import spotipy import codecs from statistics import mean sys.path.insert(0, '/home/pi/Git/SecureData') import secureData # set environment variables needed by Spotipy os.environ['SPOTIPY_CLIENT_ID'] = secureData.variable("SPOTIPY_CLIENT_ID") os.environ['SPOTIPY_CLIENT_SECRET'] = secureData.variable("SPOTIPY_CLIENT_SECRET") os.environ['SPOTIPY_REDIRECT_URI'] = 'http://localhost:8888' spotipy_username = secureData.variable("SPOTIPY_USERNAME") spotipy_playlist_id = secureData.variable("SPOTIPY_PLAYLIST_ID") songYears = [] totalTracks = -1 index = 0 def show_tracks(tracks): global index toReturn = u"" for i, item in enumerate(tracks['items']): track = item['track']