forked from ahivert/tgtg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
61 lines (49 loc) · 1.16 KB
/
Copy pathutils.py
File metadata and controls
61 lines (49 loc) · 1.16 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
from tgtg import TgtgClient
import time
import json
import requests
from constants import (
ACCESS_TOKEN,
COOKIE,
REFRESH_TOKEN,
USER_ID,
PUSHBULLET_ACCESS_TOKEN,
PUSHBULLET_PHONE_IDEN,
PUSH_TITLE,
)
def save_json(data, path):
with open(path, "w") as f:
json.dump(data, f)
def load_json(path):
with open(path, "r") as f:
return json.load(f)
def get_client():
return TgtgClient(
access_token=ACCESS_TOKEN,
refresh_token=REFRESH_TOKEN,
user_id=USER_ID,
cookie=COOKIE,
)
def time_since(start_time):
"""
Return time since start_time
"""
return time.time() - start_time
def send_push_notification(message):
"""
Send push notification.
https://github.com/rbrcsk/pushbullet.py
"""
headers = {
"Access-Token": f"{PUSHBULLET_ACCESS_TOKEN}",
"Content-Type": "application/json",
}
data = {
"type": "note",
"title": PUSH_TITLE,
"body": message,
"device_iden": PUSHBULLET_PHONE_IDEN,
}
requests.post(
"https://api.pushbullet.com/v2/pushes", headers=headers, data=json.dumps(data)
)