from selenium import webdriver
import time
#import networkx as nx
#import dataset
import pickle
import codecs
from selenium.webdriver.common.keys import Keys
import sys
import os
import time
import re
import json
import configparser, os
from os.path import expanduser

class JBrowser:

    def __init__(self):
        os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\")
        home = expanduser("~")
        print(home)
        config = configparser.ConfigParser()
        content=config.read_file(open(home+'\\test.cfg'))
        print(content)
        print(config['DEFAULT'])
        print(config.sections())
        self.userdir=config['DEFAULT'].get('userdir')


    def set_profile_path(self,profilepath):
        self.profilepath=profilepath
        option = webdriver.ChromeOptions()
        option.add_argument('--disable-web-security') 
        option.add_argument('--allow-running-insecure-content') 
        
        option.add_argument("--user-data-dir="+self.userdir+profilepath+"\\")

#        option.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\"+self.profilepath+"\\")
        self.option=option
        driver = webdriver.Chrome(options=option)
        self.driver=driver
#        executor_url = driver.command_executor._url
#        session_id = driver.session_id

    def scrolling(self,pgnum):
        ub = self.driver.find_element_by_css_selector('body')
        for i in range(pgnum):
            ub.send_keys(Keys.PAGE_DOWN)
            if pgnum>1:
                time.sleep(0.5)

    def get(self,url):
        self.driver.get(url)

    def get_driver(self):
        return self.driver

#jb=JBrowser()
#jb.set_profile_path("Profile 7")

#jb.get('https://m.facebook.com/ufi/reaction/profile/browser/?ft_ent_identifier=1981894498624379&ref=page_internal')

#time.sleep(3)
