-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclearPage.py
51 lines (40 loc) · 1.49 KB
/
clearPage.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
import sys, collections
import pymysql
from switch import switch
if __name__ == '__main__':
site = sys.argv[1]
#connect to mysql
conn = pymysql.connect(host='localhost', port=3306, user='ohmu', passwd='TGSTGSTGS', db='crts')
cur = conn.cursor()
#find site
cur.execute("SELECT id FROM sites WHERE class = '{0}'".format(site))
for row in cur.fetchall():
siteId, = row
break
#find all associated pages
pageIds = []
cur.execute("SELECT id from pages WHERE site_id = {0}".format(siteId))
for row in cur.fetchall():
pageId, = row
pageIds.append(str(pageId))
pageIdStr = ', '.join(pageIds)
#find all related components for all pages for site
compIds = []
cur.execute("SELECT component_id FROM page_components WHERE page_id IN({0})".format(pageIdStr))
for row in cur.fetchall():
compId, = row
compIds.append(str(compId))
compIdStr = ', '.join(compIds)
#delete all compoenents and their relations
if len(compIds) > 1:
cur.execute("DELETE FROM components WHERE id IN({0})".format(compIdStr))
if len(pageIds) > 1:
cur.execute("DELETE FROM page_components WHERE page_id IN({0})".format(pageIdStr))
#delete all comments
if len(pageIds) > 1:
cur.execute("DELETE FROM comments WHERE page_id IN({0})".format(pageIdStr))
#delete all pages
cur.execute("DELETE FROM pages WHERE site_id = {0}".format(siteId))
#close connections
cur.close()
conn.close()