-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarm_tracker2.py
More file actions
47 lines (40 loc) · 1.22 KB
/
farm_tracker2.py
File metadata and controls
47 lines (40 loc) · 1.22 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
#!/usr/bin/env python3
import time
import os
from subprocess import call
import yaml
import crayons
import requests
FARMSURL = "https://labs.alta3.com/demo/farms.yaml"
def clear():
# check and make call for specific operating system
_ = call('clear' if os.name =='posix' else 'cls')
def farmcount(farms):
i = 0
for farm in farms:
i += 1
return i
def farmstatus():
farmsresp = requests.get(FARMSURL)
farmlife = farmsresp.text
farms = yaml.safe_load(farmlife)
clear()
#print title in bold green
print(crayons.green(f"Old Mac has {farmcount(farms)} farms, they are:", bold=True))
# farm will be equal to one of the dict within the list "farms"
for farm in farms:
#print name of the farms in bold yellow
print(crayons.yellow(f"{farm.get('name')}, which is raising: ", bold=True))
# from a single "farm" get the list from the key "agriculture"
for agri in farm.get('agriculture'):
#print agriculture in bold blue
print(crayons.blue(f" - {agri}", bold=True))
print(crayons.green("Ctrl-c to quit"))
def main():
try:
while True:
farmstatus()
time.sleep(20)
except KeyboardInterrupt:
pass
main()