-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQL2fzIRDB_header.py
86 lines (73 loc) · 2.6 KB
/
SQL2fzIRDB_header.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
import os
import sqlite3
db_fzirdb = os.path.join(os.getcwd(), 'db', 'flipper_irdblite.db')
con = sqlite3.connect(db_fzirdb)
cur = con.cursor()
files = cur.execute("""
SELECT irf.category
,irf.brand
,irf.file
,irc.comment
,irf.md5hash
FROM irfile irf
LEFT JOIN ircomment irc ON irf.md5hash = irc.md5hash
WHERE irf.source = 'IRDB'
AND irf.category = 'TVs'
AND irf.brand = 'Hitachi'
""")
irfiles = files.fetchall()
#print(len(irfiles))
for irfile in irfiles:
irfile_arr = []
irfile_arr.append("Filetype: IR signals file")
irfile_arr.append("Version: 1")
irfile_arr.append("#")
if irfile[3]:
irfile_arr.append(irfile[3])
irfile_arr.append("#")
irfile_arr.append("# type: {}".format(irfile[0]))
irfile_arr.append("# brand: {}".format(irfile[1]))
irmodel = irfile[2].replace(".ir","").replace(irfile[1],"").replace("_","")
irfile_arr.append("# model: {} (Not known if device or remote)".format(irmodel))
irfile_arr.append("# protocol: (TBD: Protocol of btn power or max of buttons)")
irfile_arr.append("#")
buttons = cur.execute(("""
SELECT
irb.name
,IFNULL((SELECT button
FROM btntrans btrn
WHERE TRIM(irb.name) = btrn.name
AND button IS NOT ""
),irb.name) name2
,irb.type
,irb.protocol
,irb.address
,irb.command
FROM irbutton irb
WHERE irb.md5hash = '{}'
""").format(irfile[4]))
irbuttons = buttons.fetchall()
for irbutton in irbuttons:
irfile_arr.append("#")
irfile_arr.append("name: {}".format(irbutton[1]))
if irbutton[2] == 'parsed':
irfile_arr.append("type: {}".format(irbutton[2]))
irfile_arr.append("protocol: {}".format(irbutton[3]))
irfile_arr.append("address: {}".format(irbutton[4]))
irfile_arr.append("command: {}".format(irbutton[5]))
elif irbutton[2] == 'raw':
irfile_arr.append("type: {}".format(irbutton[2]))
irfile_arr.append("frequency: {}".format(irbutton[3]))
irfile_arr.append("duty_cycle: {}".format(irbutton[4]))
irfile_arr.append("data: {}".format(irbutton[5]))
else:
print("Error!)")
#print('\n'.join(irfile_arr))
print("Write {} buttons to filename {}".format(len(irbuttons),(os.path.join(os.getcwd(), irfile[0], irfile[1], irfile[2]))))
new_irdb_path = os.path.join(os.getcwd(), irfile[0])
if not os.path.exists(new_irdb_path):
os.makedirs(os.path.join(new_irdb_path, irfile[1]))
f = open(os.path.join(os.getcwd(), irfile[0], irfile[1], irfile[2]), "a")
f.write('\n'.join(irfile_arr))
f.close()
con.close()