-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushbullet_handler.py
75 lines (61 loc) · 2.74 KB
/
pushbullet_handler.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
65
66
67
68
69
70
71
72
73
74
75
import json
import requests
import os
my_directory = os.path.dirname(os.path.abspath(__file__))
with open(f'{my_directory}/secrets/keys.json') as f:
api_keys = json.load(f)
PBKEY = api_keys["Pushbullet"]["Key"]
DEVID = api_keys["Pushbullet"]["DeviceID"]
def send_analytics(req, fingerprint):
"""Sends analytics data to Pushbullet API
Args:
req (dict): Hashmap containing request information
"""
url = 'https://api.pushbullet.com/v2/pushes'
content = {
"body": f'Carrier: {req["org"]} \nOS: {req["Operating System"]} \nBrowser: {req["Browser"]} \nDate-Time: {req["Date & Time"]} \nIP: {req["ip"]}\nFingerprint: {fingerprint}',
"title": f'Someone from {req["city"]} , {req["country_name"]} visited your Website @ {req["Page"]}',
"device_iden": DEVID,
"type": "note"}
headers = {'Access-Token': PBKEY, 'content-type': 'application/json'}
requests.post(url, data=json.dumps(content), headers=headers)
def send_form(formData):
"""Sends Form data to Pushbullet API
Args:
formData (dict): Hashmap containing form data
"""
url = 'https://api.pushbullet.com/v2/pushes'
content = {
"body": f'Name: {formData["name"]} \nEmail: {formData["email"]} \nAbout: {formData["about"]} \nMessage: {formData["message"]}',
"title": "Someone sent you a message via contact form",
"device_iden": DEVID,
"type": "note"}
headers = {'Access-Token': PBKEY, 'content-type': 'application/json'}
requests.post(url, data=json.dumps(content), headers=headers)
def send_performance(name, response_time, allowed):
"""Sends Performance data to Pushbullet API
Args:
name (string): The name of the endpoint that the alert is raised for
response_time (float): The average response time for the alert
allowed (float): The allowed response time for the service
"""
url = 'https://api.pushbullet.com/v2/pushes'
content = {
"body": f'The {name} endpoint took an average of : {response_time} to compute \n while the allowed time is : {allowed}',
"title": "Performance Alert",
"device_iden": DEVID,
"type": "note"}
headers = {'Access-Token': PBKEY, 'content-type': 'application/json'}
requests.post(url, data=json.dumps(content), headers=headers)
def delete():
"""Deletes all notifications via Pushbullet API"""
url = "https://api.pushbullet.com/v2/pushes"
headers = {'Access-Token': PBKEY}
requests.delete(url, headers=headers)
# def list_devices():
# """ Lists all Devices registered with Pushbullet Account """
# headers = {'Access-Token': PBKEY}
# response = requests.get(
# 'https://api.pushbullet.com/v2/devices',
# headers=headers)
# print(response.text)