-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.py
46 lines (32 loc) · 1.26 KB
/
core.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
import datetime as time
import json
from clients import twitter
from clients import opensky
from clients import google
def watch():
now = time.datetime.now()
# Save data in storage (spreadsheet)
gspread = google.GoogleSpreadsheet()
# Get data from opensky
opensky_client = opensky.OpenskyClient()
collection = opensky_client.detect()
num = len(collection[0])
# Get last planes count for calculate risk
last_planes_count = gspread.last_planes_count()
# Post data to storage spreadsheet
gspread.post(num)
if str(num) > last_planes_count:
alert(num, last_planes_count)
def alert(num, last_planes_count):
count = "{0}".format(num)
risk = calculate_risk(num)
text = "[WAR-DETECTION] Detected " + count + " private planes flying from the Eastern Bloc to West. 🚩" + " (Yesterday there were " + last_planes_count + " planes) https://docs.google.com/spreadsheets/d/10ZeOiZoSw1cZEHwoXG1auJ6ovWI5PhyvrtlhUrOalrM"
# Send data to Twitter
twitter_client = twitter.TwitterClient()
client = twitter_client.auth()
twitter_client.post(client, text)
def calculate_risk(count):
answear = "LOW"
if count >= 500:
answear = "HIGH"
return answear