forked from NicPic86/rsir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreation script table ID_CAT .py
49 lines (41 loc) · 1.29 KB
/
creation script table ID_CAT .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
import re
import collections
import string
out_file = open("events_for_categories.txt","w")
script_sql = open("script table ID_CAT.sql","w")
result_file = open("event-category-recurrence.txt", "r")
script_sql.write("-- DROP TABLE id_cat;\n")
script_sql.write("CREATE TABLE ID_CAT(keyword VARCHAR(40), idsevent VARCHAR(1200));\n")
lines_list = result_file.readlines()
i=0
lengthList = len(lines_list)
line_new = lines_list[i]
line_list_new = line_new.split(",")
cat_new = line_list_new[1]
cat_old = line_list_new[1]
events = []
idEvent = 0
while i<=lengthList:
if i<lengthList:
cat_new = line_list_new[1]
idEvent = line_list_new[0]
line_new = lines_list[i]
line_list_new = line_new.split(",")
events.append(idEvent)
if i>=lengthList:
cat_new = "loop_terminated"
if cat_new != cat_old:
idEvent = line_list_new[0]
events.append(idEvent)
stringEvents = ""
stringSQL = ""
stringEvents = ",".join(events)
stringSQL = "INSERT INTO ID_CAT (keyword, idsevents) VALUES ('"+cat_old+"', '"+stringEvents+"');"
script_sql.write(stringSQL+"\n")
out_file.write(cat_old+":"+stringEvents+"\n")
events = []
cat_old = cat_new
i+=1
out_file.close()
script_sql.close()
print "Terminated"