|
@ -4,7 +4,7 @@ import psycopg2 |
|
|
import traceback |
|
|
import traceback |
|
|
import configparser |
|
|
import configparser |
|
|
from MarketPlaces.Utilities.utilities import * |
|
|
from MarketPlaces.Utilities.utilities import * |
|
|
|
|
|
|
|
|
|
|
|
from dateutil.relativedelta import relativedelta, FR |
|
|
|
|
|
|
|
|
def connectDataBase(): |
|
|
def connectDataBase(): |
|
|
|
|
|
|
|
@ -273,6 +273,8 @@ def create_items(cur, row, marketId, vendorId): |
|
|
|
|
|
|
|
|
if newItem: |
|
|
if newItem: |
|
|
|
|
|
|
|
|
|
|
|
# decode_decrypt_image_in_base64(row[20]) |
|
|
|
|
|
|
|
|
sql = "Insert into items (item_id, market_id, vendor_id, name_item, description_item, cve_item, ms_item, category_item, " \ |
|
|
sql = "Insert into items (item_id, market_id, vendor_id, name_item, description_item, cve_item, ms_item, category_item, " \ |
|
|
"views_item, reviews_item, rating_item, dateadded_item, btc_item, usd_item, euro_item, quantitysold_item, " \ |
|
|
"views_item, reviews_item, rating_item, dateadded_item, btc_item, usd_item, euro_item, quantitysold_item, " \ |
|
|
"quantityleft_item, shippedfrom_item, shippedto_item, lastseen_item, image_item, href_item, dateinserted_item, " \ |
|
|
"quantityleft_item, shippedfrom_item, shippedto_item, lastseen_item, image_item, href_item, dateinserted_item, " \ |
|
@ -312,7 +314,7 @@ def create_items(cur, row, marketId, vendorId): |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
|
|
# decode_decrypt_image_in_base64(recset[0][20]) |
|
|
|
|
|
|
|
|
# decode_decrypt_image_in_base64(recset[0]['image_item']) |
|
|
|
|
|
|
|
|
if (str(recset[0]['description_item']) != str(row[5] if row[5] != '-1' else None) or |
|
|
if (str(recset[0]['description_item']) != str(row[5] if row[5] != '-1' else None) or |
|
|
str(recset[0]['cve_item']) != str(row[6] if row[6] != '-1' else None) or |
|
|
str(recset[0]['cve_item']) != str(row[6] if row[6] != '-1' else None) or |
|
@ -401,24 +403,27 @@ def create_items(cur, row, marketId, vendorId): |
|
|
|
|
|
|
|
|
return itemId |
|
|
return itemId |
|
|
|
|
|
|
|
|
def create_status(cur, marketId, date, status): |
|
|
|
|
|
|
|
|
def create_status(cur, marketId, date, listings, descriptions, status): |
|
|
|
|
|
|
|
|
date = datetime.strptime(date, "%m%d%Y") |
|
|
date = datetime.strptime(date, "%m%d%Y") |
|
|
|
|
|
|
|
|
|
|
|
# getting last Fridays a reference date |
|
|
|
|
|
date_reference = date + relativedelta(weekday=FR(-1)) |
|
|
|
|
|
|
|
|
# checking if status already exists |
|
|
# checking if status already exists |
|
|
sql = "select * from marketplaces_status where market_id = %(market_id)s and date_inserted = %(date_inserted)s" |
|
|
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}) |
|
|
cur.execute(sql, {'market_id': marketId, 'date_inserted': date}) |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
if recset: |
|
|
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} |
|
|
|
|
|
|
|
|
sql = "Update marketplaces_status set listings = %(listings)s, descriptions = %(descriptions)s, status = %(status)s, date_reference = %(date_reference)s " \ |
|
|
|
|
|
"where market_id = %(market_id)s and date_inserted = %(date_inserted)s" |
|
|
|
|
|
recset = {'listings': listings, 'descriptions': descriptions, 'status': status, 'date_reference': date_reference, 'market_id': marketId, 'date_inserted': date} |
|
|
else: |
|
|
else: |
|
|
sql = "Insert into marketplaces_status (market_id, date_inserted, status) Values (%s, %s, %s)" |
|
|
|
|
|
recset = [marketId, date, status] |
|
|
|
|
|
|
|
|
sql = "Insert into marketplaces_status (market_id, date_inserted, listings, descriptions, status, date_reference) Values (%s, %s, %s, %s, %s, %s)" |
|
|
|
|
|
recset = [marketId, date, listings, descriptions, status, date_reference] |
|
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
|
def create_database(cur, con): |
|
|
def create_database(cur, con): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
@ -431,7 +436,8 @@ 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, " \ |
|
|
|
|
|
|
|
|
sql = "Create table marketplaces_status (market_id integer NOT NULL, date_inserted date NOT NULL, " \ |
|
|
|
|
|
"listings integer NOT NULL, descriptions integer NOT NULL, status bit(1) NOT NULL, date_reference date NOT NULL " \ |
|
|
"CONSTRAINT marketplaces_log_pkey PRIMARY KEY (market_id, date_inserted), " \ |
|
|
"CONSTRAINT marketplaces_log_pkey PRIMARY KEY (market_id, date_inserted), " \ |
|
|
"CONSTRAINT marketplaces_fk FOREIGN KEY (market_id) REFERENCES marketplaces (market_id))" |
|
|
"CONSTRAINT marketplaces_fk FOREIGN KEY (market_id) REFERENCES marketplaces (market_id))" |
|
|
cur.execute(sql) |
|
|
cur.execute(sql) |
|
|