Browse Source

Forums and Markets status.

main
ericssonmarin-cpp 1 year ago
parent
commit
ed5a9193e1
4 changed files with 58 additions and 0 deletions
  1. +23
    -0
      Forums/DB_Connection/db_connection.py
  2. +6
    -0
      Forums/Initialization/prepare_parser.py
  3. +23
    -0
      MarketPlaces/DB_Connection/db_connection.py
  4. +6
    -0
      MarketPlaces/Initialization/prepare_parser.py

+ 23
- 0
Forums/DB_Connection/db_connection.py View File

@ -484,6 +484,24 @@ def create_posts(cur, row, forumId, topicId):
'dateinserted_post': row[8], 'dateinserted_post': row[8],
'postId': postId}) 'postId': postId})
def create_status(cur, forumId, date, status):
date = datetime.strptime(date, "%m%d%Y")
# checking if status already exists
sql = "select * from forums_status where forum_id = %(forum_id)s and date_inserted = %(date_inserted)s"
cur.execute(sql, {'forum_id': forumId, 'date_inserted': date})
recset = cur.fetchall()
if recset:
sql = "Update forums_status set status = %(status)s where forum_id = %(forum_id)s and date_inserted = %(date_inserted)s"
recset = {'status': status, 'forum_id': forumId, 'date_inserted': date}
else:
sql = "Insert into forums_status (forum_id, date_inserted, status) Values (%s, %s, %s)"
recset = [forumId, date, status]
cur.execute(sql, recset)
def create_database(cur, con): def create_database(cur, con):
try: try:
@ -496,6 +514,11 @@ def create_database(cur, con):
sql = "create unique index unique_forum ON forums USING btree (name_forum ASC NULLS LAST)" sql = "create unique index unique_forum ON forums USING btree (name_forum ASC NULLS LAST)"
cur.execute(sql) cur.execute(sql)
sql = "Create table forums_status (forum_id integer NOT NULL, date_inserted date NOT NULL, status bit(1) NOT NULL, " \
"CONSTRAINT forums_log_pkey PRIMARY KEY (forum_id, date_inserted), " \
"CONSTRAINT forums_fk 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(" \ 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, " \ "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, " \ "interest_user character varying(5000) null, signature_user character varying(1000) null, " \


+ 6
- 0
Forums/Initialization/prepare_parser.py View File

@ -341,6 +341,12 @@ def new_parse(forum, url, createLog):
# move listing files of completed folder # move listing files of completed folder
move_file(listingFile, createLog, logFile) move_file(listingFile, createLog, logFile)
# registering the current forum status (up/down) in the database
forumId = verifyForum(cur, forum)
if (forumId > 0):
create_status(cur, forumId, CURRENT_DATE, '1' if len(listings) > 0 else '0')
con.commit()
if createLog: if createLog:
logFile.close() logFile.close()


+ 23
- 0
MarketPlaces/DB_Connection/db_connection.py View File

@ -401,6 +401,24 @@ def create_items(cur, row, marketId, vendorId):
return itemId return itemId
def create_status(cur, marketId, date, status):
date = datetime.strptime(date, "%m%d%Y")
# checking if status already exists
sql = "select * from marketplaces_status where market_id = %(market_id)s and date_inserted = %(date_inserted)s"
cur.execute(sql, {'market_id': marketId, 'date_inserted': date})
recset = cur.fetchall()
if recset:
sql = "Update marketplaces_status set status = %(status)s where market_id = %(market_id)s and date_inserted = %(date_inserted)s"
recset = {'status': status, 'market_id': marketId, 'date_inserted': date}
else:
sql = "Insert into marketplaces_status (market_id, date_inserted, status) Values (%s, %s, %s)"
recset = [marketId, date, status]
cur.execute(sql, recset)
def create_database(cur, con): def create_database(cur, con):
try: try:
@ -413,6 +431,11 @@ def create_database(cur, con):
sql = "create unique index unique_market ON marketplaces USING btree (name_market ASC NULLS LAST)" sql = "create unique index unique_market ON marketplaces USING btree (name_market ASC NULLS LAST)"
cur.execute(sql) cur.execute(sql)
sql = "Create table marketplaces_status (market_id integer NOT NULL, date_inserted date NOT NULL, status bit(1) NOT NULL, " \
"CONSTRAINT marketplaces_log_pkey PRIMARY KEY (market_id, date_inserted), " \
"CONSTRAINT marketplaces_fk FOREIGN KEY (market_id) REFERENCES marketplaces (market_id))"
cur.execute(sql)
sql = "create table vendors(vendor_id integer not null, market_id integer not null, name_vendor character " \ sql = "create table vendors(vendor_id integer not null, market_id integer not null, name_vendor character " \
"varying(255) not null, rating_vendor character varying(255), successfultransactions_vendor integer " \ "varying(255) not null, rating_vendor character varying(255), successfultransactions_vendor integer " \
"null, image_vendor character varying(10000000) null, dateinserted_vendor timestamp(6) with time zone not null, " \ "null, image_vendor character varying(10000000) null, dateinserted_vendor timestamp(6) with time zone not null, " \


+ 6
- 0
MarketPlaces/Initialization/prepare_parser.py View File

@ -363,6 +363,12 @@ def new_parse(marketPlace, url, createLog):
# move listing files of completed folder # move listing files of completed folder
move_file(listingFile, createLog, logFile) move_file(listingFile, createLog, logFile)
# registering the current forum status (up/down) in the database
marketId = verifyMarketPlace(cur, marketPlace)
if (marketId > 0):
create_status(cur, marketId, CURRENT_DATE, '1' if len(listings) > 0 else '0')
con.commit()
if createLog: if createLog:
logFile.close() logFile.close()


Loading…
Cancel
Save