-
Notifications
You must be signed in to change notification settings - Fork 7
/
Setup.py
168 lines (146 loc) · 4.84 KB
/
Setup.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import subprocess as shell
import os
import json
import mysql.connector as sql
import requests
import re
def main():
print("configを生成します")
print("録音ファイルの保存先を指定してください\nデフォルト ./savefile => ", end="")
tmp = input()
conf["all"]["savedir"] = tmp if tmp!="" else ""
print("Radikoの地域判定を行いますか? y/n => ", end="")
tmp = input()
if tmp =="y":
main_radiko()
print("lineで通知する場合はトークンを入力してください => ", end="")
tmp = input()
if tmp != "":
conf["all"]["line_token"] = tmp
print("オブジェクトストレージを使いますか? y/n => ", end="")
tmp = input()
if tmp == "y":
main_objectstorage()
print("mysqlを使いますか? y/n => ", end="")
tmp = input()
if tmp == "y":
main_mysql()
print("rcloneを使いますか? y/n => ", end="")
tmp = input()
if tmp == "y":
main_rclone()
print("./conf/config.jsonに保存しました")
with open("./conf/config.json", "w") as f:
json.dump(conf, f, ensure_ascii=False, indent=4, separators=(',', ': '))
def main_objectstorage():
conf["swift"] = {}
print("object storage swift")
print("tenantid => ", end="")
tmp = input()
conf["swift"]["tenantid"] = tmp
print("username => ", end="")
tmp = input()
conf["swift"]["username"] = tmp
print("password => ", end="")
tmp = input()
conf["swift"]["password"] = tmp
print("identityUrl => ", end="")
tmp = input()
conf["swift"]["identityUrl"] = tmp
print("objectStorageUrl => ", end="")
tmp = input()
conf["swift"]["objectStorageUrl"] = tmp
def main_mysql():
conf["mysql"] = {}
print("mysql")
print("hostname\nデフォルト localhost => ", end="")
tmp = input()
conf["mysql"]["hostname"] = tmp if tmp!="" else "localhost"
print("port\nデフォルト 3306 => ", end="")
tmp = input()
conf["mysql"]["port"] = tmp if tmp!="" else "3306"
print("username => ", end="")
tmp = input()
if tmp == "":
print("正しい値を入力してください")
exit(1)
conf["mysql"]["username"] = tmp
print("password => ", end="")
tmp = input()
if tmp == "":
print("正しい値を入力してください")
exit(1)
conf["mysql"]["password"] = tmp
print("database name => ", end="")
tmp = input()
if tmp == "":
print("正しい値を入力してください")
exit(1)
conf["mysql"]["database"] = tmp
print("テーブルを自動生成しますか?(新規インストールの方はyを入力してください)\ny/n => ", end="")
tmp = input()
if tmp == "y":
mysql_create_table()
def mysql_create_table():
try:
conn = sql.connect(
host = conf["mysql"]["hostname"],
port = conf["mysql"]["port"],
user = conf["mysql"]["username"],
password = conf["mysql"]["password"],
database = conf["mysql"]["database"]
)
cur = conn.cursor()
table = "Programs"
cur.execute("DROP TABLE IF EXISTS `%s`;", table)
cur.execute(
"""
CREATE TABLE IF NOT EXISTS `%s` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` text NOT NULL,
`pfm` text,
`rec-timestamp` datetime NOT NULL,
`station` varchar(30) DEFAULT '',
`uri` text NOT NULL,
`info` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=395 DEFAULT CHARSET=utf8;
""", table)
cur.close()
conn.close()
except:
print("Mysql setup failed")
def main_rclone():
conf["rclone"] = {}
print("rclone")
print("method => ", end="")
tmp = input()
conf["rclone"]["method"] = tmp
print("outdir => ", end="")
tmp = input()
conf["rclone"]["outdir"] = tmp
print("options => ", end="")
tmp = input()
conf["rclone"]["options"] = tmp
def main_radiko():
radiko_area = requests.get("https://radiko.jp/area")
result_no = re.search(r'JP\d+',radiko_area.text)
result_area = re.search(r'(?<=>).*\s.*(?=</span>)',radiko_area.text)
tmp = ""
if result_no:
print("Radikoの視聴地域は" + result_area.group(0) + "です。設定しますか?\ny/n => ", end="")
tmp = input()
if tmp == "y":
conf["all"]["Radiko_URL"] = "http://radiko.jp/v3/program/today/" + result_no.group(0) +".xml"
if __name__ == "__main__":
conf = {
"all": {
"savedir": "",
"Radiko_URL": "http://radiko.jp/v3/program/today/JP13.xml",
"keywords": []
},
}
main()
print("Rec-adioを使うにはffmpegが必要です。")