|
|
@ -36,7 +36,7 @@ def verifyForum(cur, nameForum): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from forums where name = %(nameForum)s limit 1", {'nameForum': nameForum}) |
|
|
|
cur.execute("select forum_id from forums where name_forum = %(nameForum)s limit 1", {'nameForum': nameForum}) |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -55,7 +55,7 @@ def verifyBoard(cur, forum, nameBoard): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from boards where forum_id = %(forum)s and name = %(nameBoard)s limit 1", |
|
|
|
cur.execute("select board_id from boards where forum_id = %(forum)s and name_board = %(nameBoard)s limit 1", |
|
|
|
{'forum': forum, 'nameBoard': nameBoard}) |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
@ -71,12 +71,15 @@ def verifyBoard(cur, forum, nameBoard): |
|
|
|
print (trace) |
|
|
|
|
|
|
|
|
|
|
|
def verifyTopic(cur, forum, board, nameTopic): |
|
|
|
def verifyTopic(cur, forumId, boardId, authorId, titleTopic): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from topics where forum_id = %(forum)s and board_id = %(board)s and " |
|
|
|
"name = %(nameTopic)s limit 1",{'forum': forum, 'board': board, 'nameTopic': nameTopic}) |
|
|
|
cur.execute("select topic_id from topics where forum_id = %(forumId)s and board_id = %(boardId)s and " |
|
|
|
"author_id = %(authorId)s and title_topic = %(titleTopic)s limit 1", {'forumId': forumId, |
|
|
|
'boardId': boardId, |
|
|
|
'authorId': authorId, |
|
|
|
'titleTopic': titleTopic}) |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -91,11 +94,12 @@ def verifyTopic(cur, forum, board, nameTopic): |
|
|
|
print (trace) |
|
|
|
|
|
|
|
|
|
|
|
def verifyUser(cur, nameUser): |
|
|
|
def verifyUser(cur, nameUser, forumId): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from users where name = %(nameUser)s limit 1", {'nameUser': nameUser}) |
|
|
|
cur.execute("select user_id from users where name_user = %(nameUser)s and forum_id = %(forumId)s limit 1", |
|
|
|
{'nameUser': nameUser, 'forumId': forumId}) |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -114,7 +118,7 @@ def getLastForum(cur): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from forums order by id desc limit 1") |
|
|
|
cur.execute("select forum_id from forums order by forum_id desc limit 1") |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -133,7 +137,7 @@ def getLastBoard(cur): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from boards order by id desc limit 1") |
|
|
|
cur.execute("select board_id from boards order by board_id desc limit 1") |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -152,7 +156,7 @@ def getLastTopic(cur): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from topics order by id desc limit 1") |
|
|
|
cur.execute("select topic_id from topics order by topic_id desc limit 1") |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -171,7 +175,7 @@ def getLastUser(cur): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
cur.execute("select id from Users order by id desc") |
|
|
|
cur.execute("select user_id from users order by user_id desc") |
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
@ -186,6 +190,7 @@ def getLastUser(cur): |
|
|
|
print (trace) |
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
|
def getLastPost(cur): |
|
|
|
|
|
|
|
try: |
|
|
@ -203,97 +208,111 @@ def getLastPost(cur): |
|
|
|
|
|
|
|
trace = traceback.format_exc() |
|
|
|
print (trace) |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
def create_forum(cur, row): |
|
|
|
|
|
|
|
forum = verifyForum(cur, row[0]) |
|
|
|
forumId = verifyForum(cur, row[0]) |
|
|
|
|
|
|
|
if not forum: |
|
|
|
if not forumId: |
|
|
|
|
|
|
|
forum = int(getLastForum(cur) + 1) |
|
|
|
forumId = int(getLastForum(cur) + 1) |
|
|
|
|
|
|
|
sql = "Insert into forums (id, name, date_Inserted) Values (%s, %s, %s)" |
|
|
|
sql = "Insert into forums (forum_id, name_forum, url_forum, dateinserted_forum) Values (%s, %s, %s, %s)" |
|
|
|
|
|
|
|
recset = [forum, row[0], time.asctime()] |
|
|
|
recset = [forumId, row[0], None, row[8]] |
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
return forum |
|
|
|
return forumId |
|
|
|
|
|
|
|
|
|
|
|
def create_board(cur, row, forum): |
|
|
|
def create_board(cur, row, forumId): |
|
|
|
|
|
|
|
board = verifyBoard(cur, forum, row[2]) |
|
|
|
boardId = verifyBoard(cur, forumId, row[1]) |
|
|
|
|
|
|
|
if not board: |
|
|
|
if not boardId: |
|
|
|
|
|
|
|
board = int(getLastBoard(cur) + 1) |
|
|
|
boardId = int(getLastBoard(cur) + 1) |
|
|
|
|
|
|
|
sql = "Insert into boards (id, forum_id, name, date_inserted) Values (%s, %s, %s, %s)" |
|
|
|
sql = "Insert into boards (board_id, forum_id, name_board, dateinserted_board) Values (%s, %s, %s, %s)" |
|
|
|
|
|
|
|
recset = [board, forum, row[2], time.asctime()] |
|
|
|
recset = [boardId, forumId, row[1], row[8]] |
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
return board |
|
|
|
|
|
|
|
return boardId |
|
|
|
|
|
|
|
def create_topic(cur, row, forum, board, user): |
|
|
|
|
|
|
|
topic = verifyTopic(cur, board, forum, row[2]) |
|
|
|
def create_topic(cur, row, forumId, boardId, authorId): |
|
|
|
|
|
|
|
if not topic: |
|
|
|
topicId = verifyTopic(cur, forumId, boardId, authorId, row[3]) |
|
|
|
|
|
|
|
topic = int(getLastTopic(cur) + 1) |
|
|
|
if not topicId: |
|
|
|
|
|
|
|
sql = "Insert into topics (id, forum_id, board_id, author_id, name, classification, date_added, date_inserted) " \ |
|
|
|
"Values (%s, %s, %s, %s, %s, %s, %s, %s)" |
|
|
|
topicId = int(getLastTopic(cur) + 1) |
|
|
|
|
|
|
|
recset = [topic, forum, board, user, row[1], row[17], row[6] if row[6]!= '-1' else None, time.asctime()] |
|
|
|
sql = "Insert into topics (topic_id, forum_id, board_id, author_id, title_topic, views_topic, posts_topic, " \ |
|
|
|
"href_topic, dateadded_topic, dateinserted_topic, classification_topic) Values (%s, %s, %s, %s, %s, %s, " \ |
|
|
|
"%s, %s, %s, %s, %s)" |
|
|
|
|
|
|
|
recset = [topicId, forumId, boardId, authorId, |
|
|
|
row[3], |
|
|
|
row[4] if row[4] != '-1' else None, |
|
|
|
row[5] if row[5] != '-1' else None, |
|
|
|
row[6] if row[6] != '-1' else None, |
|
|
|
row[7] if row[7] != '-1' else None, |
|
|
|
row[8], |
|
|
|
row[17]] |
|
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
return topic |
|
|
|
return topicId |
|
|
|
|
|
|
|
|
|
|
|
def create_user(cur, nameUser): |
|
|
|
def create_user(cur, row, forumId, index): |
|
|
|
|
|
|
|
user = verifyUser(cur, nameUser) |
|
|
|
userId = verifyUser(cur, row[9][index], forumId) |
|
|
|
|
|
|
|
if not user: |
|
|
|
if not userId: |
|
|
|
|
|
|
|
user = int(getLastUser(cur) + 1) |
|
|
|
userId = int(getLastUser(cur) + 1) |
|
|
|
|
|
|
|
sql = "Insert into users (id, name, date_Inserted) Values (%s, %s, %s)" |
|
|
|
sql = "Insert into users (user_id, forum_id, name_user, status_user, reputation_user, interest_user, " \ |
|
|
|
"signature_user, dateinserted_user) Values (%s, %s, %s, %s, %s, %s, %s, %s)" |
|
|
|
|
|
|
|
recset = [user, nameUser, time.asctime()] |
|
|
|
recset = [userId, forumId, |
|
|
|
row[9][index], |
|
|
|
row[10][index] if row[10][index] != '-1' else None, |
|
|
|
row[11][index] if row[11][index] != '-1' else None, |
|
|
|
row[12][index] if row[12][index] != '-1' else None, |
|
|
|
row[13][index] if row[13][index] != '-1' else None, |
|
|
|
row[8]] |
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
def create_posts(cur, row, forum, board, topic): |
|
|
|
return userId |
|
|
|
|
|
|
|
if row[8] != "-1": |
|
|
|
|
|
|
|
for i in range(len(row[8])): |
|
|
|
def create_posts(cur, row, forumId, boardId, topicId): |
|
|
|
|
|
|
|
id = int(getLastPost(cur) + 1) |
|
|
|
if row[9] != "-1": |
|
|
|
|
|
|
|
user = create_user(cur, row[9][i]) |
|
|
|
for i in range(len(row[9])): |
|
|
|
|
|
|
|
sql = "Insert into posts (id, forum_id, board_id, topic_id, user_id, content, rule, date_added, reputation_user, " \ |
|
|
|
"status_user, feedback_user, interest_user, date_inserted) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" |
|
|
|
if i != 0: |
|
|
|
userId = create_user(cur, row, forumId, i) |
|
|
|
else: |
|
|
|
userId = verifyUser(cur, row[2], forumId) |
|
|
|
|
|
|
|
recset = [id, forum, board, topic, user, row[8][i] if row[8][i]!= '-1' else None, |
|
|
|
row[14][i] if row[14][i]!= '-1' else None, row[10][i] if row[10][i]!= '-1' else None, |
|
|
|
row[13][i] if row[13][i]!= '-1' else None, row[12][i] if row[12][i]!= '-1' else None, |
|
|
|
row[11][i] if row[11][i]!= '-1' else None, row[15][i] if row[15][i]!= '-1' else None, |
|
|
|
sql = "Insert into posts (forum_id, board_id, topic_id, user_id, content_post, feedback_post, " \ |
|
|
|
"dateadded_post, dateinserted_post) Values (%s, %s, %s, %s, %s, %s, %s, %s)" |
|
|
|
|
|
|
|
str("%02d" %date.today().month) + "/" + str("%02d" %date.today().day) + "/" + |
|
|
|
str("%04d" %date.today().year) + " " + time.strftime("%I:%M:%S")] |
|
|
|
recset = [forumId, boardId, topicId, userId, |
|
|
|
row[14][i] if row[14][i] != '-1' else None, |
|
|
|
row[15][i] if row[15][i] != '-1' else None, |
|
|
|
row[16][i] if row[16][i] != '-1' else None, |
|
|
|
row[8]] |
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
@ -302,35 +321,62 @@ def create_database(cur, con): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
sql = "create table forums (id integer NOT NULL, name character varying(255) NOT NULL, " \ |
|
|
|
"date_inserted timestamp(6) with time zone NOT NULL, constraint forums_pk primary key (id))" |
|
|
|
sql = "create table forums (forum_id integer NOT NULL, name_forum character varying(255) NOT NULL, url_forum " \ |
|
|
|
"character varying(255) null, dateinserted_forum timestamp(6) with time zone NOT NULL, constraint " \ |
|
|
|
"forums_pk primary key (forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table boards (board_id integer NOT NULL, forum_id integer NOT NULL, name_board character " \ |
|
|
|
"varying(255) NOT NULL, dateinserted_board timestamp(6) with time zone NOT NULL, constraint boards_pk " \ |
|
|
|
"primary key (board_id), constraint boards_forum_id_fkey foreign key (forum_id) references forums (" \ |
|
|
|
"forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table users (user_id integer NOT NULL, forum_id integer NOT NULL, name_user character varying(" \ |
|
|
|
"255) NOT NULL, status_user character varying(255) null, reputation_user character varying(255) null, " \ |
|
|
|
"interest_user character varying(5000) null, signature_user character varying(1000) null, " \ |
|
|
|
"dateinserted_user timestamp(6) with time zone NOT NULL, constraint users_pk primary key (user_id), " \ |
|
|
|
"constraint users_forum_id_fkey foreign key (forum_id) references forums (forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table boards (id integer NOT NULL, forum_id integer NOT NULL, name character varying(255) NOT NULL," \ |
|
|
|
"date_inserted timestamp(6) with time zone NOT NULL, constraint boards_pk primary key (id), " \ |
|
|
|
"constraint boards_forum_id_fkey foreign key (forum_id) references forums (id))" |
|
|
|
sql = "create table users_history(user_id integer NOT NULL, forum_id integer NOT NULL, name_user character " \ |
|
|
|
"varying(255) NOT NULL, status_user character varying(255) null, reputation_user character varying(255) " \ |
|
|
|
"null, interest_user character varying(5000) null, signature_user character varying(1000) null, " \ |
|
|
|
"dateinserted_user timestamp(6) with time zone NOT NULL, constraint users_history_pk primary key (" \ |
|
|
|
"user_id, dateinserted_user), constraint users_history_user_id_fkey foreign key (user_id) references " \ |
|
|
|
"users (user_id), constraint users_history_forum_id_fkey foreign key (forum_id) references forums (" \ |
|
|
|
"forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table users (id integer NOT NULL, name character varying(255) NOT NULL, " \ |
|
|
|
"date_inserted timestamp(6) with time zone NOT NULL, constraint users_pk primary key (id))" |
|
|
|
sql = "create table topics(topic_id integer NOT NULL, forum_id integer NOT NULL, board_id integer NOT NULL, " \ |
|
|
|
"author_id integer NOT NULL, title_topic character varying(255) NOT NULL, views_topic integer null, " \ |
|
|
|
"posts_topic integer null, href_topic character varying(255) null, dateadded_topic timestamp(6) with " \ |
|
|
|
"time zone null, dateinserted_topic timestamp(6) with time zone NOT NULL, classification_topic double " \ |
|
|
|
"precision NOT NULL, constraint topics_pk primary key (topic_id), constraint topics_author_id_fkey " \ |
|
|
|
"foreign key (author_id) references users (user_id), constraint topics_board_id_fkey foreign key (" \ |
|
|
|
"board_id) references boards (board_id), constraint topics_forum_id_fkey foreign key (forum_id) " \ |
|
|
|
"references forums (forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table topics(id integer NOT NULL, forum_id integer NOT NULL, board_id integer NOT NULL, " \ |
|
|
|
"author_id integer NOT NULL, name character varying(255) NOT NULL, classification double precision not null, " \ |
|
|
|
"date_added timestamp(6) with time zone, date_inserted timestamp(6) with time zone NOT NULL, " \ |
|
|
|
"constraint topics_pk primary key (id), constraint topics_author_id_fkey foreign key (author_id) references users (id), " \ |
|
|
|
"constraint topics_board_id_fkey foreign key (board_id) references boards (id), " \ |
|
|
|
"constraint topics_forum_id_fkey foreign key (forum_id) references forums (id))" |
|
|
|
sql = "create table topics_history(topic_id integer NOT NULL, forum_id integer NOT NULL, board_id integer NOT " \ |
|
|
|
"NULL, author_id integer NOT NULL, title_topic character varying(255) NOT NULL, views_topic integer " \ |
|
|
|
"null, posts_topic integer null, href_topic character varying(255) null, dateadded_topic timestamp(6) " \ |
|
|
|
"with time zone null, dateinserted_topic timestamp(6) with time zone NOT NULL, classification_topic " \ |
|
|
|
"double precision NOT NULL, constraint topics_history_pk primary key (topic_id, dateinserted_topic), " \ |
|
|
|
"constraint topics_history_topic_id_fkey foreign key (topic_id) references topics (topic_id), " \ |
|
|
|
"constraint topics_history_author_id_fkey foreign key (author_id) references users (user_id), " \ |
|
|
|
"constraint topics_history_board_id_fkey foreign key (board_id) references boards (board_id), " \ |
|
|
|
"constraint topics_history_forum_id_fkey foreign key (forum_id) references forums (forum_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
sql = "create table posts(id integer NOT NULL, forum_id integer NOT NULL, board_id integer NOT NULL, " \ |
|
|
|
"topic_id integer NOT NULL, user_id integer NOT NULL, content character varying(100000), rule character varying(5000), " \ |
|
|
|
"reputation_user character varying(100), status_user character varying(255), feedback_user integer, " \ |
|
|
|
"interest_user character varying(1000), date_added timestamp(6) with time zone, date_inserted timestamp(6) with time zone NOT NULL, " \ |
|
|
|
"constraint posts_pk primary key (id), constraint posts_author_id_fkey foreign key (user_id) references users (id), " \ |
|
|
|
"constraint posts_board_id_fkey foreign key (board_id) references boards (id), " \ |
|
|
|
"constraint posts_forum_id_fkey foreign key (forum_id) references forums (id)," \ |
|
|
|
"constraint posts_topic_id_fkey foreign key (topic_id) references topics (id))" |
|
|
|
sql = "create table posts(forum_id integer NOT NULL, board_id integer NOT NULL, topic_id integer NOT NULL, " \ |
|
|
|
"user_id integer NOT NULL, content_post character varying(100000) null, feedback_post integer null, " \ |
|
|
|
"dateadded_post timestamp(6) with time zone NOT NULL, dateinserted_post timestamp(6) with time zone NOT " \ |
|
|
|
"NULL, constraint posts_pk primary key (forum_id, board_id, topic_id, user_id, dateadded_post), " \ |
|
|
|
"constraint posts_author_id_fkey foreign key (user_id) references users (user_id), constraint " \ |
|
|
|
"posts_board_id_fkey foreign key (board_id) references boards (board_id), constraint " \ |
|
|
|
"posts_forum_id_fkey foreign key (forum_id) references forums (forum_id), constraint " \ |
|
|
|
"posts_topic_id_fkey foreign key (topic_id) references topics (topic_id))" |
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
con.commit() |
|
|
|