forked from sun-yryr/Rec-adio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·109 lines (100 loc) · 3.41 KB
/
run.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from lib import radiko, agqr, onsen, hibiki, functions as f
import subprocess
from multiprocessing import Process
from signal import SIGINT
import signal
import time
import datetime as DT
import json
import requests
import re
import os
SAVEROOT = ""
T_BASELINE = DT.timedelta(seconds=60)
T_ZERO = DT.timedelta()
keywords = []
def main_radiko():
Radiko = radiko.radiko()
Radiko.change_keywords(keywords)
radiko_data = Radiko.search()
while(True):
now = DT.datetime.now()
#print(radiko_data)
if (bool(radiko_data)):
for data in radiko_data:
tmp_time = data["DT_ft"] - now
if (tmp_time < T_ZERO):
radiko_data.remove(data)
elif (tmp_time < T_BASELINE):
AuthToken = Radiko.authorization()
p = Process(target=Radiko.rec, args=([data, tmp_time.total_seconds(), AuthToken, SAVEROOT],))
p.start()
radiko_data.remove(data)
if (now.hour == 6 and now.minute <= 5 and Radiko.reload_date != DT.date.today()):
Radiko.reload_program()
radiko_data = Radiko.search()
time.sleep(60)
def main_agqr():
Agqr = agqr.agqr()
Agqr.change_keywords(keywords)
agqr_data = Agqr.search()
#print(agqr_data)
while(True):
now = DT.datetime.now()
if (bool(agqr_data)):
for data in agqr_data:
tmp_time = data["DT_ft"] - now
if (tmp_time < T_ZERO):
agqr_data.remove(data)
elif (tmp_time < T_BASELINE):
p = Process(target=Agqr.rec, args=([data, tmp_time.total_seconds(), SAVEROOT],))
p.start()
agqr_data.remove(data)
if (now.hour == 0 and now.minute <= 5 and Agqr.reload_date != DT.date.today()):
Agqr.reload_program()
agqr_data = Agqr.search()
time.sleep(60)
def main_hibiki():
Hibiki = hibiki.hibiki(keywords, SAVEROOT)
while(True):
now = DT.datetime.now()
if (now.hour == 7 and now.minute <= 5 and Hibiki.reload_date != DT.date.today()):
titles = Hibiki.rec()
if (bool(titles)):
f.LINE.recording_successful_toline("、".join(titles))
else:
print("hibiki. there aren't new title.")
time.sleep(300)
def main_onsen():
Onsen = onsen.onsen(keywords, SAVEROOT)
while(True):
now = DT.datetime.now()
if (now.hour == 7 and now.minute <= 5 and Onsen.reload_date != DT.date.today()):
titles = Onsen.rec()
if (bool(titles)):
f.LINE.recording_successful_toline("、".join(titles))
else:
print("in onsen. there aren't new title.")
time.sleep(300)
def signalHandler(signal, handler) :
for i in ps:
i.terminate()
exit(0)
if __name__ == "__main__":
config = f.load_configurations()
SAVEROOT = f.createSaveDirPath(config["all"]["savedir"])
print("SAVEROOT : " + SAVEROOT)
keywords = config["all"]["keywords"]
ps = [
Process(target=main_radiko),
Process(target=main_agqr),
Process(target=main_hibiki)
]
signal.signal(signal.SIGINT, signalHandler)
signal.signal(signal.SIGTERM, signalHandler)
for i in ps:
i.start()
while(True):
time.sleep(1)