-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlistAllPages.py
More file actions
64 lines (47 loc) · 1.53 KB
/
listAllPages.py
File metadata and controls
64 lines (47 loc) · 1.53 KB
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
import pymysql
import png
import platform
import time
import sys
from switch import switch
def ListPages(cur, comicId, domain, pageParam):
cur.execute("SELECT id, uri_path FROM pages WHERE site_id={0} ORDER BY id ASC".format(comicId))
path = domain + '.list' #this is the "domain" field in the database + '.list'
#we are running on windows, use ./ as path
if platform.system() == 'Windows':
path = './' + path
#we are running on server, use /usr/local/bin/ as path
else :
path = '/usr/local/bin/' + path
try:
f = open(path, 'w')
for row in cur.fetchall():
id, uri = row
f.write(("http://" + domain + pageParam + "\n").format(uri))
#finally close file
f.close()
except Exception as e:
print(e)
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()
cur.execute("SELECT id, domain FROM sites WHERE class='{0}'".format(site))
for row in cur.fetchall():
id, domain = row
break
for case in switch(site):
if case('XKCD'):
ListPages(cur, id, domain, '{0}')
break
if case('DoomsDayMyDear'):
ListPages(cur, id, domain, '{0}')
break
if case():
print ("That site isn't recognized!")
break
#more cases here
#close connections
cur.close()
conn.close()