__author__ = 'DarkWeb'

'''
Starting point of the Darkweb Mining Platform
'''

import os
from datetime import *
from MarketPlaces.DarkFox.crawler_selenium import crawler as crawlerDarkFox
from MarketPlaces.Tor2door.crawler_selenium import crawler as crawlerTor2door
from MarketPlaces.ThiefWorld.crawler_selenium import crawler as crawlerThiefWorld
from MarketPlaces.TorBay.crawler_selenium import crawler as crawlerTorBay
from MarketPlaces.LionMarketplace.crawler_selenium import crawler as crawlerLionMarketplace
from MarketPlaces.TorMarket.crawler_selenium import crawler as crawlerTorMarket
from MarketPlaces.MikesGrandStore.crawler_selenium import crawler as crawlerMikesGrandStore
from MarketPlaces.DarkTor.crawler_selenium import crawler as crawlerDarkTor
from MarketPlaces.DigitalThriftShop.crawler_selenium import crawler as crawlerDigitalThriftShop
from MarketPlaces.AnonymousMarketplace.crawler_selenium import crawler as crawlerAnonymousMarketplace
from MarketPlaces.Apocalypse.crawler_selenium import crawler as crawlerApocalypseMarketplace
from MarketPlaces.CityMarket.crawler_selenium import crawler as crawlerCityMarket
from MarketPlaces.DarkMatter.crawler_selenium import crawler as crawlerDarkMatter
from MarketPlaces.M00nkeyMarket.crawler_selenium import crawler as crawlerM00nkeyMarket



import time

CURRENT_DATE = str("%02d" % date.today().month) + str("%02d" % date.today().day) + str("%04d" % date.today().year)


# reads list of marketplaces
def getMarkets():
    mkts = []
    with open('MarketsList.txt') as f:
        mkts = f.readlines()
    return mkts


# Creates needed directories for marketplace if doesn't exist
def createDirectory(mkt):

    # Package should already be there, holding crawler and parser
    pagesDir = '../' + mkt + '/HTML_Pages'
    if not os.path.isdir(pagesDir):
        os.makedirs(pagesDir)

    currentDateDir = pagesDir + '/' + CURRENT_DATE
    if not os.path.isdir(currentDateDir):
        os.mkdir(currentDateDir)

    listingDir = currentDateDir + '/Listing'
    if not os.path.isdir(listingDir):
        os.mkdir(listingDir)

    listReadDir = listingDir + '/Read'
    if not os.path.isdir(listReadDir):
        os.mkdir(listReadDir)

    descriptionDir = currentDateDir + '/Description'
    if not os.path.isdir(descriptionDir):
        os.mkdir(descriptionDir)

    descReadDir = descriptionDir + '/Read'
    if not os.path.isdir(descReadDir):
        os.mkdir(descReadDir)


if __name__ == '__main__':
    mktsList = getMarkets()

    for mkt in mktsList:
        mkt = mkt.replace('\n','')

        print("Creating listing and description directories ...")
        createDirectory(mkt)
        time.sleep(5)
        input("Directories created successfully. Press ENTER to continue\n")

        if mkt == "DarkFox":
            crawlerDarkFox()
        elif mkt == 'Tor2door':
            crawlerTor2door()
        elif mkt == "ThiefWorld":
            crawlerThiefWorld()
        elif mkt == "TorBay":
            crawlerTorBay()
        elif mkt == "LionMarketplace":
            crawlerLionMarketplace()
        elif mkt == "TorMarket":
            crawlerTorMarket()
        elif mkt == "MikesGrandStore":
            crawlerMikesGrandStore()
        elif mkt == "DarkTor":
            crawlerDarkTor()
        elif mkt == "DigitalThriftShop":
            crawlerDigitalThriftShop()
        elif mkt == "AnonymousMarketplace":
            crawlerAnonymousMarketplace()
        elif mkt == "Apocalypse":
            crawlerApocalypseMarketplace()
        elif mkt == "CityMarket":
            crawlerCityMarket()
        elif mkt == "DarkMatter":
            crawlerDarkMatter()
        elif mkt == "M00nkeyMarket":
            crawlerM00nkeyMarket()



    print("Scraping process completed successfully!")
