-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
64 lines (47 loc) · 1.88 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import subprocess
import os
from os.path import join, dirname
from dotenv import load_dotenv
from datetime import datetime
import requests
from coinbase.wallet.client import Client
import dht
import bme280
# The client requires non-empty values for authentication, even though the call
# we're making does not require it.
coinbase_client = Client("a", "1")
# Create .env file path.
dotenv_path = join(dirname(__file__), '.env')
# Load file from the path.
load_dotenv(dotenv_path)
PC_MAC_ADDRESS = os.getenv('PC_MAC_ADDRESS')
def wake_pc(channel):
subprocess.run('wakeonlan ${PC_MAC_ADDRESS}', shell=True)
def get_people_in_space():
space_people = requests.get('https://www.howmanypeopleareinspacerightnow.com/peopleinspace.json', headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:76.0) Gecko/20100101 Firefox/76.0'})
return 'PiS: ' + str(space_people.json()['number'])
def get_bitcoin_usd_price():
try:
bitcoin_price = coinbase_client.get_spot_price(currency_pair = 'BTC-USD')
return 'BTC: ' + f'{float(bitcoin_price.amount):,.0f}' + ' USD'
except:
return 'BTC: Error'
def get_current_datetime():
now = datetime.now().astimezone().replace(microsecond=0)
return now.strftime('%m/%d %I:%M%P')
def get_device_ip_address():
return subprocess.run(['hostname', '-I'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip(' \n')
def get_temp_and_humidity():
measurements = bme280.get_measurements()
if not measurements:
return ''
return "{:.1f}º F / {:.1f}º C, RH: {}%".format(
measurements['temperature_f'], measurements['temperature_c'], measurements['humidity']
)
def get_pressure_and_altitude():
measurements = bme280.get_measurements()
if not measurements:
return ''
return "{:.1f} hPa / {:.2f} meters".format(
measurements['pressure'], measurements['altitude']
)