|
@ -5,24 +5,6 @@ import traceback |
|
|
import time |
|
|
import time |
|
|
from datetime import date |
|
|
from datetime import date |
|
|
|
|
|
|
|
|
''' |
|
|
|
|
|
vendors |
|
|
|
|
|
add |
|
|
|
|
|
mk_id |
|
|
|
|
|
vendor_rating |
|
|
|
|
|
successful_transactions |
|
|
|
|
|
|
|
|
|
|
|
products |
|
|
|
|
|
add |
|
|
|
|
|
product_rating |
|
|
|
|
|
|
|
|
|
|
|
remove |
|
|
|
|
|
date_item |
|
|
|
|
|
escrow_info |
|
|
|
|
|
last_viewed |
|
|
|
|
|
vendor_rating |
|
|
|
|
|
successful_transaction |
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
def connectDataBase(): |
|
|
def connectDataBase(): |
|
|
|
|
|
|
|
@ -40,7 +22,7 @@ def verifyMarketPlace(cur, nameMarket): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
cur.execute("select id_mk from marketPlaces where name_mk = %(nameMarket)s limit 1", {'nameMarket': nameMarket}) |
|
|
|
|
|
|
|
|
cur.execute("select market_id from marketPlaces where name_market = %(nameMarket)s limit 1", {'nameMarket': nameMarket}) |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
|
@ -55,11 +37,12 @@ def verifyMarketPlace(cur, nameMarket): |
|
|
print (trace) |
|
|
print (trace) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def verifyVendor(cur, nameVendor): |
|
|
|
|
|
|
|
|
def verifyVendor(cur, nameVendor, marketId): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
cur.execute("select id_ve from vendors where name_ve = %(nameVendor)s limit 1", {'nameVendor': nameVendor}) |
|
|
|
|
|
|
|
|
cur.execute("select vendor_id from vendors where name_vendor = %(nameVendor)s and market_id = %(marketId)s " |
|
|
|
|
|
"limit 1", {'nameVendor': nameVendor, 'marketId': marketId}) |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
|
@ -78,7 +61,7 @@ def getLastMarketPlace(cur): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
cur.execute("select id_mk from marketPlaces order by id_mk desc limit 1") |
|
|
|
|
|
|
|
|
cur.execute("select market_id from marketPlaces order by market_id desc limit 1") |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
|
@ -97,7 +80,7 @@ def getLastVendor(cur): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
cur.execute("select id_ve from vendors order by id_ve desc limit 1") |
|
|
|
|
|
|
|
|
cur.execute("select vendor_id from vendors order by vendor_id desc limit 1") |
|
|
|
|
|
|
|
|
recset = cur.fetchall() |
|
|
recset = cur.fetchall() |
|
|
|
|
|
|
|
@ -114,54 +97,70 @@ def getLastVendor(cur): |
|
|
|
|
|
|
|
|
def create_marketPlace(cur, row): |
|
|
def create_marketPlace(cur, row): |
|
|
|
|
|
|
|
|
marketPlace = verifyMarketPlace(cur, row[0]) |
|
|
|
|
|
|
|
|
marketId = verifyMarketPlace(cur, row[0]) |
|
|
|
|
|
|
|
|
if not marketPlace: |
|
|
|
|
|
marketPlace = int(getLastMarketPlace(cur) + 1) |
|
|
|
|
|
|
|
|
if not marketId: |
|
|
|
|
|
marketId = int(getLastMarketPlace(cur) + 1) |
|
|
|
|
|
|
|
|
sql = "Insert into marketPlaces (id_mk, name_mk, url_mk, dateInserted) Values (%s, %s, %s, %s)" |
|
|
|
|
|
|
|
|
sql = "Insert into marketplaces (market_id, name_market, url_market, dateinserted_market) " \ |
|
|
|
|
|
"Values (%s, %s, %s, %s)" |
|
|
|
|
|
|
|
|
recset = [marketPlace, row[0], None, time.asctime()] |
|
|
|
|
|
|
|
|
recset = [marketId, row[0], None, row[21]] |
|
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
|
return marketPlace |
|
|
|
|
|
|
|
|
return marketId |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_vendor(cur, row): |
|
|
|
|
|
|
|
|
def create_vendor(cur, row, marketId): |
|
|
|
|
|
|
|
|
vendor = verifyVendor(cur, row[18]) |
|
|
|
|
|
|
|
|
vendorId = verifyVendor(cur, row[1], marketId) |
|
|
|
|
|
|
|
|
if not vendor: |
|
|
|
|
|
vendor = int(getLastVendor(cur) + 1) |
|
|
|
|
|
|
|
|
if not vendorId: |
|
|
|
|
|
vendorId = int(getLastVendor(cur) + 1) |
|
|
|
|
|
|
|
|
sql = "Insert into vendors (id_ve, name_ve, dateInserted) Values (%s, %s, %s)" |
|
|
|
|
|
|
|
|
sql = "Insert into vendors (vendor_id, market_id, name_vendor, rating_vendor, successfultransactions_vendor, dateinserted_vendor) Values (%s, %s, %s, %s, %s, %s)" |
|
|
|
|
|
|
|
|
recset = [vendor, row[18], time.asctime()] |
|
|
|
|
|
|
|
|
recset = [vendorId, marketId, |
|
|
|
|
|
row[1], |
|
|
|
|
|
row[2] if row[2] != '-1' else None, |
|
|
|
|
|
row[3] if row[3] != '-1' else None, |
|
|
|
|
|
row[21]] |
|
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
|
return vendor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_items(cur, row, marketPlace, vendor): |
|
|
|
|
|
|
|
|
|
|
|
sql = "Insert into items (id_mk, id_ve, date_item, name_item, description_item, cve_item, ms_item, category_item, " \ |
|
|
|
|
|
"escrowinfo_item, views_item, reviews_item, addeddate_item, lastvieweddate_item, btcsellingprice_item, usdsellingprice_item, " \ |
|
|
|
|
|
"eurosellingprice_item, quantitysold_item, quantityleft_item, shippedfrom_item, shippedto_item, vendorrating, successfulltransactions, " \ |
|
|
|
|
|
"termsandconditions, dateinserted_item, classification_item) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, " \ |
|
|
|
|
|
"%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" |
|
|
|
|
|
|
|
|
|
|
|
recset = [marketPlace, vendor, str("%02d" %date.today().month) + "/" + str("%02d" %date.today().day) + "/" + str("%04d" %date.today().year), |
|
|
|
|
|
#recset = [marketPlace, vendor, str("%02d" %date.today().day) + "/" + str("%02d" %date.today().month) + "/" + str("%04d" %date.today().year), |
|
|
|
|
|
row[1] if row[1]!= '-1' else None, row[5] if row[5]!= '-1' else None, row[2] if row[2]!= '-1' else None, |
|
|
|
|
|
row[3] if row[3]!= '-1' else None, row[4] if row[4]!= '-1' else None, row[6] if row[6]!= '-1' else None, |
|
|
|
|
|
row[7] if row[7]!= '-1' else None, row[8] if row[8]!= '-1' else None, row[9] if row[9]!= '-1' else None, |
|
|
|
|
|
row[10] if row[10]!= '-1' else None, row[11] if row[11]!= '-1' else None, row[12] if row[12]!= '-1' else None, |
|
|
|
|
|
row[13] if row[13]!= '-1' else None, row[14] if row[14]!= '-1' else None, row[15] if row[15]!= '-1' else None, |
|
|
|
|
|
row[16] if row[16]!= '-1' else None, row[17] if row[17]!= '-1' else None, row[19] if row[19]!= '-1' else None, |
|
|
|
|
|
row[20] if row[20]!= '-1' else None, row[21] if row[21]!= '-1' else None, row[22] if row[22]!= '-1' else None, |
|
|
|
|
|
row[24] if row[24]!= '-1' else None] |
|
|
|
|
|
|
|
|
return vendorId |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_items(cur, row, marketId, vendorId): |
|
|
|
|
|
|
|
|
|
|
|
sql = "Insert into items (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, " \ |
|
|
|
|
|
"quantityleft_item, shippedfrom_item, shippedto_item, href_item, lastseen_item, dateinserted_item, " \ |
|
|
|
|
|
"classification_item) Values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, " \ |
|
|
|
|
|
"%s, %s, %s)" |
|
|
|
|
|
|
|
|
|
|
|
recset = [marketId, vendorId, |
|
|
|
|
|
row[4], |
|
|
|
|
|
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] if row[8] != '-1' else None, |
|
|
|
|
|
row[9] if row[9] != '-1' else None, |
|
|
|
|
|
row[10] if row[10] != '-1' else None, |
|
|
|
|
|
row[11] if row[11] != '-1' else None, |
|
|
|
|
|
row[12] if row[12] != '-1' else None, |
|
|
|
|
|
row[13] if row[13] != '-1' else None, |
|
|
|
|
|
row[14] if row[14] != '-1' else None, |
|
|
|
|
|
row[15] if row[15] != '-1' else None, |
|
|
|
|
|
row[16] if row[16] != '-1' else None, |
|
|
|
|
|
row[17] if row[17] != '-1' else None, |
|
|
|
|
|
row[18] if row[18] != '-1' else None, |
|
|
|
|
|
row[19] if row[19] != '-1' else None, |
|
|
|
|
|
row[20] if row[20] != '-1' else None, |
|
|
|
|
|
row[21], |
|
|
|
|
|
row[21], |
|
|
|
|
|
row[22]] |
|
|
|
|
|
|
|
|
cur.execute(sql, recset) |
|
|
cur.execute(sql, recset) |
|
|
|
|
|
|
|
@ -170,26 +169,53 @@ def create_database(cur, con): |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
|
|
|
|
|
|
sql = "create table marketplaces(id_mk integer not null, name_mk character varying(255) not null, " \ |
|
|
|
|
|
"url_mk character varying(255) null, dateinserted timestamp(6) with time zone not null, " \ |
|
|
|
|
|
"constraint pk_mk primary key (id_mk))" |
|
|
|
|
|
|
|
|
sql = "create table marketplaces(market_id integer not null, name_market character varying(255) not null, " \ |
|
|
|
|
|
"url_market character varying(255) null, dateinserted_market timestamp(6) with time zone not null, " \ |
|
|
|
|
|
"constraint markets_pk primary key (market_id))" |
|
|
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
|
|
|
|
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 " \ |
|
|
|
|
|
"null, dateinserted_vendor timestamp(6) with time zone not null, constraint vendors_pk primary key (" \ |
|
|
|
|
|
"vendor_id), constraint vendors_market_id_fkey foreign key (market_id) references marketplaces (" \ |
|
|
|
|
|
"market_id))" |
|
|
|
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
|
|
|
|
sql = "create table vendors_history(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 null, dateinserted_vendor timestamp(6) with time zone not null, constraint vendors_history_pk " \ |
|
|
|
|
|
"primary key (vendor_id, dateinserted_vendor), constraint vendors_history_vendor_id_fkey foreign key (" \ |
|
|
|
|
|
"vendor_id) references vendors (vendor_id), constraint vendors_history_market_id_fkey foreign key (" \ |
|
|
|
|
|
"market_id) references marketplaces (market_id))" |
|
|
cur.execute(sql) |
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
|
sql = "create table vendors(id_ve integer not null, name_ve character varying(255) not null, " \ |
|
|
|
|
|
"dateinserted timestamp(6) with time zone not null, constraint pk_ve primary key (id_ve))" |
|
|
|
|
|
|
|
|
sql = "create table items(market_id integer not null, vendor_id integer not null, name_item character " \ |
|
|
|
|
|
"varying(255) not null, description_item character varying(1000000) null, cve_item character varying(" \ |
|
|
|
|
|
"255) null, ms_item character varying(255) null, category_item character varying(255) null, views_item " \ |
|
|
|
|
|
"integer null, reviews_item integer null, rating_item character varying(255) null, dateadded_item " \ |
|
|
|
|
|
"character varying(25) null, btc_item character varying(255) null, usd_item character varying(255) " \ |
|
|
|
|
|
"null, euro_item character varying(255) null, quantitysold_item integer null, quantityleft_item " \ |
|
|
|
|
|
"character varying(255) null, shippedfrom_item character varying(255) null, shippedto_item character " \ |
|
|
|
|
|
"varying(255) null, href_item character varying(255) null, lastseen_item timestamp(6) with time zone " \ |
|
|
|
|
|
"not null, dateinserted_item timestamp(6) with time zone not null, classification_item double " \ |
|
|
|
|
|
"precision not null, constraint items_pk primary key (market_id, vendor_id, name_item), constraint " \ |
|
|
|
|
|
"items_market_id_fkey foreign key (market_id) references marketplaces (market_id),constraint " \ |
|
|
|
|
|
"items_vendor_id_fkey foreign key (vendor_id) references vendors (vendor_id))" |
|
|
cur.execute(sql) |
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
|
sql = "create table items(id_mk integer not null, id_ve integer not null, date_item date not null, name_item character varying(255) not null, " \ |
|
|
|
|
|
"description_item character varying(1000000) null, cve_item character varying(255) null, ms_item character varying(255) null, " \ |
|
|
|
|
|
"category_item character varying(255) null, escrowinfo_item character varying(1000) null, views_item integer null, " \ |
|
|
|
|
|
"reviews_item character varying(255) null, addeddate_item character varying(25) null, " \ |
|
|
|
|
|
"lastvieweddate_item character varying(25) null, btcsellingprice_item character varying(255) null, " \ |
|
|
|
|
|
"usdsellingprice_item character varying(255) null, eurosellingprice_item character varying(255) null, quantitysold_item integer null, " \ |
|
|
|
|
|
"quantityleft_item character varying(255) null, shippedfrom_item character varying(255) null, shippedto_item character varying(5000) null, " \ |
|
|
|
|
|
"vendorrating character varying(255) null, successfulltransactions character varying(500) null, " \ |
|
|
|
|
|
"termsandconditions character varying(15000) null, dateinserted_item timestamp(6) with time zone not null, " \ |
|
|
|
|
|
"classification_item double precision not null, constraint pk_items primary key (id_mk, id_ve, date_item, name_item), " \ |
|
|
|
|
|
"constraint items_id_mk_fkey foreign key (id_mk) references marketplaces (id_mk),constraint items_id_ve_fkey foreign key (id_ve) references vendors (id_ve))" |
|
|
|
|
|
|
|
|
sql = "create table items_history(market_id integer not null, vendor_id integer not null, name_item character " \ |
|
|
|
|
|
"varying(255) not null, description_item character varying(1000000) null, cve_item character varying(" \ |
|
|
|
|
|
"255) null, ms_item character varying(255) null, category_item character varying(255) null, views_item " \ |
|
|
|
|
|
"integer null, reviews_item integer null, rating_item character varying(255) null, dateadded_item " \ |
|
|
|
|
|
"character varying(25) null, btc_item character varying(255) null, usd_item character varying(255) " \ |
|
|
|
|
|
"null, euro_item character varying(255) null, quantitysold_item integer null, quantityleft_item " \ |
|
|
|
|
|
"character varying(255) null, shippedfrom_item character varying(255) null, shippedto_item character " \ |
|
|
|
|
|
"varying(255) null, href_item character varying(255) null, lastseen_item timestamp(6) with time zone " \ |
|
|
|
|
|
"not null, dateinserted_item timestamp(6) with time zone not null, classification_item double " \ |
|
|
|
|
|
"precision not null, constraint items_history_pk primary key (market_id, vendor_id, name_item, " \ |
|
|
|
|
|
"dateinserted_item), constraint items_history_market_id_fkey foreign key (market_id) references " \ |
|
|
|
|
|
"marketplaces (market_id), constraint items_history_vendor_id_fkey foreign key (vendor_id) references " \ |
|
|
|
|
|
"vendors (vendor_id))" |
|
|
cur.execute(sql) |
|
|
cur.execute(sql) |
|
|
|
|
|
|
|
|
con.commit() |
|
|
con.commit() |
|
|