-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMastoPost.py
More file actions
72 lines (67 loc) · 2.05 KB
/
MastoPost.py
File metadata and controls
72 lines (67 loc) · 2.05 KB
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
65
66
67
68
69
70
71
72
from mastodon import Mastodon
import configparser
import argparse
import sys
import os
import SoilModule as soilmodule
from THModule import readTHModule
from CameraModule import photo
#import Logger
confFile = os.path.join(os.path.dirname(__file__), 'conf.secret')
confParser = configparser.RawConfigParser()
confParser.read(confFile)
# Read in arguments
parser = argparse.ArgumentParser()
parser.add_argument('-s','--soil',help='read soil moisture',action='store_true')
parser.add_argument('-a','--atmosphere',help='read temperature & humidity',action='store_true')
parser.add_argument('-c','--camera',help='take a photo',action='store_true')
parser.add_argument('-A','--All',help='poll camera and all sensors',action='store_true')
args = parser.parse_args()
# Login
apiURL = confParser.get('growbot-conf', 'apiURL')
clientSecret = os.path.join(os.path.dirname(__file__), 'growbot_client.secret')
userSecret = os.path.join(os.path.dirname(__file__), 'growbot_user.secret')
username = confParser.get('growbot-conf', 'username')
password = confParser.get('growbot-conf', 'password')
user = Mastodon(
client_id = clientSecret,
api_base_url = apiURL
)
user.log_in(username, password, to_file=userSecret)
user = Mastodon(
access_token = userSecret,
api_base_url = apiURL
)
# Format data and post it
outstr = ''
if args.All or args.atmosphere:
try:
thmod = readTHModule()
outstr += 'Temp: '+thmod[0]+'f'
outstr += ' '
outstr += 'Humidity: '+thmod[1]
except Exception as e:
print(e)
outstr += e
pass
finally:
outstr += '\n\n'
if args.All or args.soil:
try:
smmod = soilmodule.readSoilMoisture()
for i in range(len(smmod)-1):
outstr += '['+i+'] '+smmod[i]
except:
pass
finally:
outstr += '\n'
if args.All or args.camera:
user.status_post(
outstr,
media_ids=user.media_post(photo()))
exit(0)
else:
sys.stderr.write('growbot-x: INVALID ARGUMENT FORMAT FOR MASTOPOST\n')
exit(1)
user.status_post(outstr)
exit(0)