import unittest
from mangawalk.scraping.comick import ComicK
from mangawalk.scraping.types.type_comick import *
import time
from catswalk.scraping.types.type_webdriver import *
from catswalk.utils.functional import calc_time
import os

class TestComicK(unittest.TestCase):
    binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    executable_path = "/Users/rv/ws/tools/chromedriver"
    proxy = None
    headless = True
    url_list = ["https://comic.k-manga.jp/title/95912/pv", "https://comic.k-manga.jp/title/94017/pv", "https://comic.k-manga.jp/title/109519/pv"]


    def get_url_list(self):
        input_url = os.getcwd() + "/input/manga_target.csv"
        with open(input_url) as f:
            url_list = f.read().split("\n")
        return url_list

    @calc_time()
    def test_get_pv(self):
        """[python -m unittest tests.scraping.test_comick.TestComicK.test_get_pv]
        """
        request = ComicK(binary_location=self.binary_location, executable_path=self.executable_path, execution_env=EXECUTION_ENV.LOCAL_HEADLESS)
        request.init()
        result = request.get_pv("https://comic.k-manga.jp/title/95912/pv").to_csv()
        print(result)
        time.sleep(10)
    
    @calc_time()
    def test_get_pvs(self):
        """[python -m unittest tests.scraping.test_comick.TestComicK.test_get_pvs]
        """
        #request = ComicK(binary_location=self.binary_location, executable_path=self.executable_path, execution_env=EXECUTION_ENV.LOCAL_HEADLESS, device = DEVICE.MOBILE_GALAXY_S5)
        #request.init()
        url_list = self.get_url_list()
        results = ComicK.get_pvs(self.url_list)
        print(results)

    @calc_time()
    def test_save_comiclist_img(self):
        """[python -m unittest tests.scraping.test_comick.TestComicK.test_save_comiclist_img]
        """
        request = ComicK(binary_location=self.binary_location, executable_path=self.executable_path, execution_env=EXECUTION_ENV.LOCAL_HEADLESS,  device = DEVICE.MOBILE_GALAXY_S5)
        request.init()
        results = request.save_comiclist_img("/Users/rv/Desktop", "https://comic.k-manga.jp/title/95912/pv")
        print(results)
        time.sleep(10)

    @calc_time()
    def test_output_pvs(self):
        """[python -m unittest tests.scraping.test_comick.TestComicK.test_output_pvs]
        """
        request = ComicK(binary_location=self.binary_location, executable_path=self.executable_path, execution_env=EXECUTION_ENV.LOCAL_HEADLESS,  device = DEVICE.MOBILE_GALAXY_S5)
        request.init()
        base_path = os.getcwd() + "/output"
        url_list = self.get_url_list()
        request.output_pvs(url_list, base_path)

    @calc_time()
    def test_get_rank(self):
        """[python -m unittest tests.scraping.test_comick.TestComicK.test_get_rank]
        """
        rr = ComicK.get_rank()
        for r in rr:
            print(r)
        #time.sleep(10)


if __name__ == "__main__":
    unittest.main()