from flask import Flask, request, session, render_template, send_file app = Flask(__name__) from urllib import parse import json import pymysql import time import re import bcrypt import os import difflib json_data = open('set.json').read() data = json.loads(json_data) print('오픈나무 시작 포트 : ' + data['port']) import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app.config['MAX_CONTENT_LENGTH'] = int(data['upload']) * 1024 * 1024 try: conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8mb4') curs = conn.cursor(pymysql.cursors.DictCursor) try: curs.execute("select * from data limit 1") except: curs.execute("create table data(title text not null, data longtext not null, acl text not null)") try: curs.execute("select * from history limit 1") except: curs.execute("create table history(id text not null, title text not null, data longtext not null, date text not null, ip text not null, send text not null, leng text not null)") try: curs.execute("select * from rd limit 1") except: curs.execute("create table rd(title text not null, sub text not null, date text not null)") try: curs.execute("select * from user limit 1") except: curs.execute("create table user(id text not null, pw text not null, acl text not null)") try: curs.execute("select * from ban limit 1") except: curs.execute("create table ban(block text not null, end text not null, why text not null, band text not null)") try: curs.execute("select * from topic limit 1") except: curs.execute("create table topic(id text not null, title text not null, sub text not null, data longtext not null, date text not null, ip text not null, block text not null)") try: curs.execute("select * from stop limit 1") except: curs.execute("create table stop(title text not null, sub text not null, close text not null)") try: curs.execute("select * from rb limit 1") except: curs.execute("create table rb(block text not null, end text not null, today text not null, blocker text not null, why text not null)") try: curs.execute("select * from login limit 1") except: curs.execute("create table login(user text not null, ip text not null, today text not null)") try: curs.execute("select * from back limit 1") except: curs.execute("create table back(title text not null, link text not null, type text not null)") try: curs.execute("select * from cat limit 1") except: curs.execute("create table cat(title text not null, cat text not null)") except: conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], charset = 'utf8mb4') curs = conn.cursor(pymysql.cursors.DictCursor) curs.execute("create database " + data['db']) curs.execute("alter database " + data['db'] + " character set = utf8mb4 collate = utf8mb4_unicode_ci") curs.execute("use " + data['db']) try: curs.execute("select * from data limit 1") except: curs.execute("create table data(title text not null, data longtext not null, acl text not null)") try: curs.execute("select * from history limit 1") except: curs.execute("create table history(id text not null, title text not null, data longtext not null, date text not null, ip text not null, send text not null, leng text not null)") try: curs.execute("select * from rd limit 1") except: curs.execute("create table rd(title text not null, sub text not null, date text not null)") try: curs.execute("select * from user limit 1") except: curs.execute("create table user(id text not null, pw text not null, acl text not null)") try: curs.execute("select * from ban limit 1") except: curs.execute("create table ban(block text not null, end text not null, why text not null, band text not null)") try: curs.execute("select * from topic limit 1") except: curs.execute("create table topic(id text not null, title text not null, sub text not null, data longtext not null, date text not null, ip text not null, block text not null)") try: curs.execute("select * from stop limit 1") except: curs.execute("create table stop(title text not null, sub text not null, close text not null)") try: curs.execute("select * from rb limit 1") except: curs.execute("create table rb(block text not null, end text not null, today text not null, blocker text not null, why text not null)") try: curs.execute("select * from login limit 1") except: curs.execute("create table login(user text not null, ip text not null, today text not null)") try: curs.execute("select * from back limit 1") except: curs.execute("create table back(title text not null, link text not null, type text not null)") try: curs.execute("select * from cat limit 1") except: curs.execute("create table cat(title text not null, cat text not null)") app.secret_key = data['key'] ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif']) def show_diff(seqm): output= [] for opcode, a0, a1, b0, b1 in seqm.get_opcodes(): if opcode == 'equal': output.append(seqm.a[a0:a1]) elif opcode == 'insert': output.append("" + seqm.b[b0:b1] + "") elif opcode == 'delete': output.append("" + seqm.a[a0:a1] + "") return ''.join(output) def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS def admincheck(): if(session.get('Now') == True): ip = getip(request) curs.execute("select * from user where id = '" + pymysql.escape_string(ip) + "'") rows = curs.fetchall() if(rows): if(rows[0]['acl'] == 'owner' or rows[0]['acl'] == 'admin'): return 1 def namumark(title, data): data = re.sub('<', '<', data) data = re.sub('>', '>', data) data = re.sub('"', '"', data) jjjj = 0 while True: p = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL) m = p.search(data) if(m): results = m.groups() q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL) n = q.search(results[0]) w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL) a = w.search(results[0]) e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL) b = e.search(results[0]) r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL) c = r.search(results[0]) t = re.compile("^#(\w+)\s(.*)$", re.DOTALL) d = t.search(results[0]) qqq = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL) qqe = qqq.search(results[0]) qqw = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL) qqa = qqw.search(results[0]) qwe = re.compile("^@(\w+)\s(.*)$", re.DOTALL) qsd = qwe.search(results[0]) qawe = re.compile("^#!noin\s(.*)$", re.DOTALL) qasd = qawe.search(results[0]) y = re.compile("^#!wiki\sstyle="((?:(?!"|\n).)*)"\n?\s\n(.*)$", re.DOTALL) l = y.search(results[0]) ppp = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL) ooo = ppp.search(results[0]) if(n): result = n.groups() data = p.sub('' + result[1] + '', data, 1) elif(a): result = a.groups() data = p.sub('' + result[1] + '', data, 1) elif(b): result = b.groups() data = p.sub('' + result[1] + '', data, 1) elif(c): result = c.groups() data = p.sub('' + result[1] + '', data, 1) elif(d): result = d.groups() data = p.sub('' + result[1] + '', data, 1) elif(qqe): result = qqe.groups() data = p.sub('' + result[1] + '', data, 1) elif(qqa): result = qqa.groups() data = p.sub('' + result[1] + '', data, 1) elif(qsd): result = qsd.groups() data = p.sub('' + result[1] + '', data, 1) elif(l): result = l.groups() data = p.sub('
' + results[0] + '', data, 1)
else:
break
while True:
a = re.compile("(((?!<\/code>).)*)<\/code>", re.DOTALL)
m = a.search(data)
if(m):
g = m.groups()
j = re.sub("<\/span>", "}}}", g[0])
j = re.sub("<\/div>", "}}}", j)
j = re.sub('', "{{{+\g ", j)
j = re.sub('', "{{{-\g ", j)
j = re.sub('', "{{{#\g ", j)
j = re.sub('', "{{{@\g ", j)
j = re.sub('', "{{{#!wiki style="\g"\n", j)
j = re.sub("(?P.)", "\g ", j)
data = a.sub(j, data, 1)
else:
break
data = re.sub("<", "<", data)
data = re.sub(">", ">", data)
data = re.sub("\[anchor\((?P[^\[\]]*)\)\]", '', data)
data = re.sub('\[date\(now\)\]', getnow(), data)
while True:
m = re.search("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", data)
if(m):
results = m.groups()
if(results[0] == title):
data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "" + results[0] + "", data, 1)
else:
curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
rows = curs.fetchall()
if(rows):
curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'include'")
abb = curs.fetchall()
if(not abb):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', 'include')")
conn.commit()
enddata = rows[0]['data']
enddata = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "", enddata)
enddata = re.sub('<', '<', enddata)
enddata = re.sub('>', '>', enddata)
enddata = re.sub('"', '"', enddata)
while True:
p = re.compile("{{{((?:(?!{)(?!}).)*)}}}", re.DOTALL)
m = p.search(enddata)
if(m):
nnn = m.groups()
q = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
n = q.search(nnn[0])
w = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
a = w.search(nnn[0])
e = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
b = e.search(nnn[0])
r = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
c = r.search(nnn[0])
t = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
d = t.search(nnn[0])
qqq = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
qqe = qqq.search(nnn[0])
qqw = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
qqa = qqw.search(nnn[0])
qwe = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
qsd = qwe.search(nnn[0])
qawe = re.compile("^#!noin\s(.*)$", re.DOTALL)
qasd = qawe.search(nnn[0])
y = re.compile("^#!wiki\sstyle="((?:(?!"|\n).)*)"\n?\s\n(.*)$", re.DOTALL)
l = y.search(nnn[0])
ppp = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
ooo = ppp.search(nnn[0])
if(n):
result = n.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(a):
result = a.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(b):
result = b.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(c):
result = c.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(d):
result = d.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(qqe):
result = qqe.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(qqa):
result = qqa.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(qsd):
result = qsd.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(l):
result = l.groups()
enddata = p.sub('' + result[1] + '', enddata, 1)
elif(ooo):
result = ooo.groups()
enddata = p.sub("" + result[0] + "[펼치기]", enddata, 1)
jjjj = jjjj + 3
elif(qasd):
enddata = p.sub("", enddata, 1)
else:
enddata = p.sub('' + nnn[0] + '', enddata, 1)
else:
break
while True:
a = re.compile("(((?!<\/code>).)*)<\/code>", re.DOTALL)
m = a.search(enddata)
if(m):
g = m.groups()
j = re.sub("<\/span>", "}}}", g[0])
j = re.sub("<\/div>", "}}}", j)
j = re.sub('', "{{{+\g ", j)
j = re.sub('', "{{{-\g ", j)
j = re.sub('', "{{{#\g ", j)
j = re.sub('', "{{{@\g ", j)
j = re.sub('', "{{{#!wiki style="\g"\n", j)
j = re.sub("(?P.)", "\g ", j)
enddata = a.sub(j, enddata, 1)
else:
break
enddata = re.sub("<", "<", enddata)
enddata = re.sub(">", ">", enddata)
if(results[1]):
a = results[1]
while True:
g = re.search("([^= ,]*)\=([^,]*)", a)
if(g):
result = g.groups()
enddata = re.sub("@" + result[0] + "@", result[1], enddata)
a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
else:
break
data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", '' + enddata + '\n', data, 1)
else:
data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "[[" + results[0] + "]]", data, 1)
else:
break
while True:
m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data)
if(m):
results = m.groups()
aa = re.search("^(.*)(#(?:.*))$", results[0])
if(aa):
results = aa.groups()
data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '', data, 1)
else:
data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '', data, 1)
curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'redirect'")
abb = curs.fetchall()
if(not abb):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', 'redirect')")
conn.commit()
else:
break
data = '\n' + data + '\n'
while True:
m = re.search("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", data)
if(m):
result = m.groups()
blockquote = result[0]
blockquote = re.sub("\n>\s?", "\n", blockquote)
data = re.sub("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", "\n" + blockquote + "
", data, 1)
else:
break
m = re.search('\[목차\]', data)
if(not m):
data = re.sub("(?P(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g", data, 1)
i = 0
h0c = 0
h1c = 0
h2c = 0
h3c = 0
h4c = 0
h5c = 0
last = 0
rtoc = '목차
'
while True:
i = i + 1
m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
if(m):
result = m.groups()
wiki = len(result[0])
if(last < wiki):
last = wiki
else:
last = wiki;
if(wiki == 1):
h1c = 0
h2c = 0
h3c = 0
h4c = 0
h5c = 0
elif(wiki == 2):
h2c = 0
h3c = 0
h4c = 0
h5c = 0
elif(wiki == 3):
h3c = 0
h4c = 0
h5c = 0
elif(wiki == 4):
h4c = 0
h5c = 0
elif(wiki == 5):
h5c = 0
if(wiki == 1):
h0c = h0c + 1
elif(wiki == 2):
h1c = h1c + 1
elif(wiki == 3):
h2c = h2c + 1
elif(wiki == 4):
h3c = h3c + 1
elif(wiki == 5):
h4c = h4c + 1
else:
h5c = h5c + 1
toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.'
toc = re.sub("(?P[0-9]0(?:[0]*)?)\.", '\g#.', toc)
toc = re.sub("0\.", '', toc)
toc = re.sub("#\.", '.', toc)
toc = re.sub("\.$", '', toc)
rtoc = rtoc + '' + toc + '. ' + result[1] + '
'
c = re.sub(" $", "", result[1])
data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '' + toc + '. ' + c + ' [편집] ', data, 1);
else:
rtoc = rtoc + ' '
break
data = re.sub("\[목차\]", rtoc, data)
category = ''
while True:
m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
if(m):
g = m.groups()
if(not title == g[0]):
curs.execute("select * from cat where title = '" + pymysql.escape_string(g[0]) + "' and cat = '" + pymysql.escape_string(title) + "'")
abb = curs.fetchall()
if(not abb):
curs.execute("insert into cat (title, cat) value ('" + pymysql.escape_string(g[0]) + "', '" + pymysql.escape_string(title) + "')")
conn.commit()
if(category == ''):
category = category + '' + re.sub("분류:", "", g[0]) + ''
else:
category = category + ' / ' + '' + re.sub("분류:", "", g[0]) + ''
data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
else:
break
data = re.sub("'''(?P.+?)'''(?!')", '\g ', data)
data = re.sub("''(?P.+?)''(?!')", '\g ', data)
data = re.sub('~~(?P.+?)~~(?!~)', '\g', data)
data = re.sub('--(?P.+?)--(?!-)', '\g', data)
data = re.sub('__(?P.+?)__(?!_)', '\g ', data)
data = re.sub('\^\^(?P.+?)\^\^(?!\^)', '\g ', data)
data = re.sub(',,(?P.+?),,(?!,)', '\g ', data)
data = re.sub('<math>(?P((?!<math>).)*)<\/math>', '$\g$', data)
data = re.sub('{{\|(?P(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '\g
', data)
data = re.sub('\[ruby\((?P[^\|]*)\|(?P[^\)]*)\)\]', '\g ', data)
data = re.sub("##\s?(?P[^\n]*)\n", "", data);
while True:
m = re.search("\[\[파일:((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
if(m):
c = m.groups()
if(c[1]):
n = re.search("width=([^ \n&]*)", c[1])
e = re.search("height=([^ \n&]*)", c[1])
if(n):
a = n.groups()
width = a[0]
else:
width = ''
if(e):
b = e.groups()
height = b[0]
else:
height = ''
img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c[0])
data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '
', data, 1)
else:
img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c[0])
data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "
", data, 1)
if(not re.search("^파일:([^\n]*)", title)):
curs.execute("select * from back where title = '" + pymysql.escape_string(c[0]) + "' and link = '" + pymysql.escape_string(title) + "' and type = 'redirect'")
abb = curs.fetchall()
if(not abb):
curs.execute("insert into back (title, link, type) value ('파일:" + pymysql.escape_string(c[0]) + "', '" + pymysql.escape_string(title) + "', 'file')")
conn.commit()
else:
break
data = re.sub("\[br\]",'
', data);
while True:
m = re.search("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", data)
if(m):
result = m.groups()
if(result[1]):
if(result[2]):
width = result[1]
height = result[2]
else:
width = result[1]
height = '315'
elif(result[2]):
if(result[3]):
height = result[2]
width = result[3]
else:
height = result[2]
width = '560'
else:
width = '560'
height = '315'
data = re.sub("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", '', data, 1)
else:
break
data = re.sub("\[\[(?::(?P(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g]]", data)
while True:
m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
if(m):
result = m.groups()
a = re.search("((?:(?!\|).)*)\|(.*)", result[0])
if(a):
results = a.groups()
aa = re.search("^(.*)(#(?:.*))$", results[0])
if(aa):
g = results[1]
results = aa.groups()
b = re.search("^http(?:s)?:\/\/", results[0])
if(b):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + g + '', data, 1)
else:
if(results[0] == title):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + g + '', data, 1)
else:
curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
rows = curs.fetchall()
if(rows):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + g + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + g + '', data, 1)
curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
rows = curs.fetchall()
if(not rows):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', '')")
conn.commit()
else:
b = re.search("^http(?:s)?:\/\/", results[0])
if(b):
c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", results[0])
if(c):
img = results[0]
img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", img)
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[1] + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[1] + '', data, 1)
else:
if(results[0] == title):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[1] + '', data, 1)
else:
curs.execute("select * from data where title = '" + pymysql.escape_string(results[0]) + "'")
rows = curs.fetchall()
if(rows):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[1] + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + results[1] + '', data, 1)
curs.execute("select * from back where title = '" + pymysql.escape_string(results[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
rows = curs.fetchall()
if(not rows):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(results[0]) + "', '" + pymysql.escape_string(title) + "', '')")
conn.commit()
else:
aa = re.search("^(.*)(#(?:.*))$", result[0])
if(aa):
result = aa.groups()
b = re.search("^http(?:s)?:\/\/", result[0])
if(b):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + result[1] + '', data, 1)
else:
if(result[0] == title):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + result[1] + '', data, 1)
else:
curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'")
rows = curs.fetchall()
if(rows):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + result[1] + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + result[1] + '', data, 1)
curs.execute("select * from back where title = '" + pymysql.escape_string(result[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
rows = curs.fetchall()
if(not rows):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(result[0]) + "', '" + pymysql.escape_string(title) + "', '')")
conn.commit()
else:
b = re.search("^http(?:s)?:\/\/", result[0])
if(b):
c = re.search("(?:\.jpg|\.png|\.gif|\.jpeg)", result[0])
if(c):
img = result[0]
img = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", img)
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + img + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1)
else:
if(result[0] == title):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1)
else:
curs.execute("select * from data where title = '" + pymysql.escape_string(result[0]) + "'")
rows = curs.fetchall()
if(rows):
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1)
else:
data = re.sub('\[\[(((?!\]\]).)*)\]\]', '' + result[0] + '', data, 1)
curs.execute("select * from back where title = '" + pymysql.escape_string(result[0]) + "' and link = '" + pymysql.escape_string(title) + "'")
rows = curs.fetchall()
if(not rows):
curs.execute("insert into back (title, link, type) value ('" + pymysql.escape_string(result[0]) + "', '" + pymysql.escape_string(title) + "', '')")
conn.commit()
else:
break
while True:
m = re.search("(http(?:s)?:\/\/(?:(?:(?:(?!\.jpg|\.png|\.gif|\.jpeg|#jpg#|#png#|#gif#|#jpeg#).)*)(?:\.jpg|\.png|\.gif|\.jpeg)))(?:(?:(?:\?)width=((?:[0-9]*)(?:px|%)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px|%)?))?(?:(?:&)width=((?:[0-9]*)(?:px|%)?))?)?", data)
if(m):
result = m.groups()
if(result[1]):
if(result[2]):
width = result[1]
height = result[2]
else:
width = result[1]
height = ''
elif(result[2]):
if(result[3]):
height = result[2]
width = result[3]
else:
height = result[2]
width = ''
else:
width = ''
height = ''
c = result[0]
c = re.sub("\.(?Pjpg|png|gif|jpeg)", "#\g#", c)
data = re.sub("(http(?:s)?:\/\/(?:(?:(?:(?!\.jpg|\.png|\.gif|\.jpeg|#jpg#|#png#|#gif#|#jpeg#).)*)(?:\.jpg|\.png|\.gif|\.jpeg)))(?:(?:(?:\?)width=((?:[0-9]*)(?:px)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px)?))?(?:(?:&)width=((?:[0-9]*)(?:px)?))?)?", "
", data, 1)
else:
break
while True:
m = re.search("((?:(?:\s\*\s[^\n]*)\n?)+)", data)
if(m):
result = m.groups()
end = str(result[0])
end = re.sub("\s\*\s(?P[^\n]*)", "\g ", end)
end = re.sub("\n", '', end)
data = re.sub("((?:(?:\s\*\s[^\n]*)\n?)+)", '' + end + '
', data, 1)
else:
break
data = re.sub('\[date\]', getnow(), data)
data = re.sub("#(?Pjpg|png|gif|jpeg)#", ".\g", data)
data = re.sub("-{4,11}", "
", data)
while True:
b = re.search("\r\n( +)", data)
if(b):
result = b.groups()
tp = len(result[0])
up = ''
i = 0
while True:
up = up + ''
i = i + 1
if(i == tp):
break
data = re.sub("\r\n( +)", '
' + up, data, 1)
else:
break
a = 1
tou = "
"
while True:
b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data)
if(b):
results = b.groups()
if(results[0]):
c = results[1]
c = re.sub("<(?:[^>]*)>", '', c)
tou = tou + "[" + results[0] + "] " + results[1] + "
"
data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", "[" + results[0] + "]", data, 1)
else:
c = results[1]
c = re.sub("<(?:[^>]*)>", '', c)
tou = tou + "[" + str(a) + "] " + results[1] + "
"
data = re.sub("\[\*([^\s]*)\s(((?!\]).)*)\]", '[' + str(a) + ']', data, 1)
a = a + 1
else:
tou = tou + ''
if(tou == "
"):
tou = ""
break
data = re.sub("\[각주\](?:(?:
| |\r|\n)+)?$", "", data)
data = re.sub("\[각주\]", "
" + tou, data)
data = data + tou
if(category):
data = data + '분류: ' + category + ''
while True:
m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
if(m):
results = m.groups()
table = results[0]
while True:
a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table)
if(a):
row = ''
cel = ''
celstyle = ''
rowstyle = ''
alltable = ''
result = a.groups()
if(result[1]):
q = re.search("<table\s?width=((?:(?!>).)*)>", result[1])
w = re.search("<table\s?height=((?:(?!>).)*)>", result[1])
e = re.search("<table\s?align=((?:(?!>).)*)>", result[1])
alltable = 'style="'
celstyle = 'style="'
rowstyle = 'style="'
if(q):
resultss = q.groups()
alltable = alltable + 'width:' + resultss[0] + ';'
if(w):
resultss = w.groups()
alltable = alltable + 'height:' + resultss[0] + ';'
if(e):
resultss = e.groups()
if(resultss[0] == 'right'):
alltable = alltable + 'margin-left:auto;'
elif(resultss[0] == 'center'):
alltable = alltable + 'margin:auto;'
else:
alltable = alltable + 'margin-right:auto;'
ee = re.search("<table\s?textalign=((?:(?!>).)*)>", result[1])
if(ee):
resultss = ee.groups()
if(resultss[0] == 'right'):
alltable = alltable + 'text-align:right;'
elif(resultss[0] == 'center'):
alltable = alltable + 'text-align:center;'
else:
alltable = alltable + 'text-align:left;'
r = re.search("<-((?:(?!>).)*)>", result[1])
if(r):
resultss = r.groups()
cel = 'colspan="' + resultss[0] + '"'
else:
cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
t = re.search("<\|((?:(?!>).)*)>", result[1])
if(t):
resultss = t.groups()
row = 'rowspan="' + resultss[0] + '"'
ba = re.search("<rowbgcolor=(#[0-9a-f-A-F]{6})>", result[1])
bb = re.search("<rowbgcolor=(#[0-9a-f-A-F]{3})>", result[1])
bc = re.search("<rowbgcolor=(\w+)>", result[1])
if(ba):
resultss = ba.groups()
rowstyle = rowstyle + 'background:' + resultss[0] + ';'
elif(bb):
resultss = bb.groups()
rowstyle = rowstyle + 'background:' + resultss[0] + ';'
elif(bc):
resultss = bc.groups()
rowstyle = rowstyle + 'background:' + resultss[0] + ';'
z = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{6})>", result[1])
x = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{3})>", result[1])
c = re.search("<table\s?bordercolor=(\w+)>", result[1])
if(z):
resultss = z.groups()
alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
elif(x):
resultss = x.groups()
alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
elif(c):
resultss = c.groups()
alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
aq = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
aw = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
ae = re.search("<table\s?bgcolor=(\w+)>", result[1])
if(aq):
resultss = aq.groups()
alltable = alltable + 'background:' + resultss[0] + ';'
elif(aw):
resultss = aw.groups()
alltable = alltable + 'background:' + resultss[0] + ';'
elif(ae):
resultss = ae.groups()
alltable = alltable + 'background:' + resultss[0] + ';'
j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
l = re.search("<bgcolor=(\w+)>", result[1])
if(j):
resultss = j.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
elif(k):
resultss = k.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
elif(l):
resultss = l.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1])
ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1])
ac = re.search("<(\w+)>", result[1])
if(aa):
resultss = aa.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
elif(ab):
resultss = ab.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
elif(ac):
resultss = ac.groups()
celstyle = celstyle + 'background:' + resultss[0] + ';'
qa = re.search("<width=((?:(?!>).)*)>", result[1])
qb = re.search("<height=((?:(?!>).)*)>", result[1])
if(qa):
resultss = qa.groups()
celstyle = celstyle + 'width:' + resultss[0] + ';'
if(qb):
resultss = qb.groups()
celstyle = celstyle + 'height:' + resultss[0] + ';'
i = re.search("<\)>", result[1])
o = re.search("<:>", result[1])
p = re.search("<\(>", result[1])
if(i):
celstyle = celstyle + 'text-align:right;'
elif(o):
celstyle = celstyle + 'text-align:center;'
elif(p):
celstyle = celstyle + 'text-align:left;'
alltable = alltable + '"'
celstyle = celstyle + '"'
rowstyle = rowstyle + '"'
table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "