def start(self, capabilities, port='9000', driver_name='chrome', host='http://127.0.0.1'): ''' Starts the webdriver and creates the session :param capabilities: The capabilities to run the session :param port: the port where the web driver will run :param driver_name: chrome (more to come soon...) :param host: by default 127.0.0.1 if you want to run this from another site put your host. :return: X ''' self.webdriver_exec.launch_driver(port, driver_name) self.host = host + ':' + port + '/' response = requests.request( 'POST', self.host + 'session', data=json.dumps(capabilities).encode('utf8')) self.session_id = json.loads(response.text)[ 'sessionId'] # Todo: see if session_id variable is necesary self.request_url = self.host + 'session/' + self.session_id self.interactions = Interactions(self.host, self.session_id) self.elements = Elements(self.host, self.session_id) self.browser = Browser(self.request_url)
def main(): """ Global variable for Chrome web driver """ global driver print('running script..') driver = webdriver.Chrome( '/Users/shouvick-koley/Desktop/InstaBot/chromedriver') l = login.Login(driver, username, password) l.signin() driver.get('') it = Interactions.Interactions(driver) refs = it.get_followers() print(it.get_num_flw()) run_bot(refs, driver, it)
def _fill_in_data(self,docked_dir, ensemble_dir, glob_pattern): # assume same names for receptor and docked results receptor_ensemble = glob.glob(ensemble_dir+ '/' + glob_pattern) # quick fix, truncate '-boxj' from 'cluster-xxxx-boxj.pdbqt' receptor_ensemble.sort() all_residues = [] self._ensemble_size = len(receptor_ensemble) receptor_states_by_residue = {} for rec in receptor_ensemble: itable = {} base = os.path.basename(rec) # if there are many docked results for the same receptor ligs = glob.glob(docked_dir+ '/' + base[:base.find(".")] + '*.pdbqt') # remove extension, add * to make regexp for li in ligs: vinaio = VinaIO(receptor_pdbqt=rec,docked_pdbqt=docked_dir+ '/' + base) pick_out = 'tmp.pdbqt' vinaio.write_conformation(pick_out,1) cmd_params = command_line_parameters("") d = Interactions(pick_out,rec,cmd_params) self.binding_energies.append(d.binding_energy) self.docked_ligands.append(d.ligand) self.centers_of_geometry.append(d.ligand.functions.centroid( *[ d.ligand.AllAtoms[i].coordinates for i in d.ligand.AllAtoms ] ) ) self.centers_of_mass.append(d.ligand.functions.center_of_mass( *[ d.ligand.AllAtoms[i] for i in d.ligand.AllAtoms ] )) # ----Data fill-in----------------------------- # elec = d.electrostatic_interactions() # for i in elec: # print i.receptor_atom.residue + " " + str(i.receptor_atom.resid) for i in d: # print i.receptor_atom.residue + " " + str(i.receptor_atom.resid) res = Residue(i.receptor_atom.residue, i.receptor_atom.resid) if res not in all_residues: all_residues.append(res) # if receptor_states_by_residue.has_key(res): receptor_states_by_residue[res].append(os.path.basename(d.receptor_pdbqt_filename)) else: receptor_states_by_residue[res] = [os.path.basename(d.receptor_pdbqt_filename)] # if itable.has_key(res): if not (itable[res].has_key(i.type)): itable[res][i.type] = [] itable[res][i.type].append(i) else: itable[res] = {i.type: [i]} # --------------------------------------------- os.system('rm %s' % pick_out) self.interaction_tables.append(itable) self._all_residues = tuple(all_residues) self._receptor_states_by_residue = receptor_states_by_residue
def checkAnswer(self,*args): self.draw() self.selectedAnswer= self.menu.checkAnswer() print(self.selectedAnswer) villager = self.village.bMap[self.wVillager].villager setter = interactions.interact(villager,self.selectedAnswer,root,C1,self.village) try: if setter[0] == "shop": self.timerRun = False self.shopScreen = setter[1] else: try: self.menu = setter[0] self.talkBox = setter[1] except: del self.menu del self.talkBox self.timerStart = True root.bind("<a>", self.onLeftPress) root.bind("<d>", self.onRightPress) root.bind("<w>", self.onUpPress) root.bind("<s>", self.onDownPress) root.bind("<Return>") root.bind("<Left>", self.onLeftPress) root.bind("<Right>", self.onRightPress) root.bind("<Up>", self.onUpPress) root.bind("<Down>", self.onDownPress) except: del self.menu del self.talkBox self.timerStart = True root.bind("<a>", self.onLeftPress) root.bind("<d>", self.onRightPress) root.bind("<w>", self.onUpPress) root.bind("<s>", self.onDownPress) root.bind("<Return>") root.bind("<Left>", self.onLeftPress) root.bind("<Right>", self.onRightPress) root.bind("<Up>", self.onUpPress) root.bind("<Down>", self.onDownPress)
# Only runs if there are any new mentions if len(mentions) > 0: for mention in mentions: # Username of person that @ the bot tweeter = "@" + mention["username"] tweet_id = mention["tweet_id"] # Removes all text before mention and then parses later text into list instruction = mention["text"].split( '@markoving_bot, 1')[0].split()[1:] # If instruction is not in interaction dictionary if len(instruction) is 0 or instruction[0].lower( ) not in Interactions.function_names.keys(): Interactions.dont_understand(bot, sql, chain, mention) else: # Calls the interaction function user_function = Interactions.function_names[ instruction[0].lower()] user_function(bot, sql, chain, mention) if int(tweet_id) > int(latest_mention): latest_mention = tweet_id # Saves last_mention to a file in case program needs to be restarted with open("last_mention_id.txt", "w+") as f: f.write(latest_mention) # Determines if it has been three hours since previous post current_time = datetime.datetime.now() time_passed = current_time - latest_post
def reset(self): self.ball = Elements.Base() self.player1 = Elements.Player() self.player2 = Elements.Player() self.inter = Interactions.Interactions() self.cage = Elements.Box(20, 20, (100, 100))
class Driver: ''' This class is the Cherry Driver. With this you will interact with your browser Methods ------- start: Runs the webdriver close_browser: Closes the browser... it is obvious... ''' def __init__(self): self.host = '' self.session_id = '' self.interactions = '' self.elements = '' self.browser = '' self.webdriver_exec = WebDriverExecutioner() self.request_url = '' def start(self, capabilities, port='9000', driver_name='chrome', host='http://127.0.0.1'): ''' Starts the webdriver and creates the session :param capabilities: The capabilities to run the session :param port: the port where the web driver will run :param driver_name: chrome (more to come soon...) :param host: by default 127.0.0.1 if you want to run this from another site put your host. :return: X ''' self.webdriver_exec.launch_driver(port, driver_name) self.host = host + ':' + port + '/' response = requests.request( 'POST', self.host + 'session', data=json.dumps(capabilities).encode('utf8')) self.session_id = json.loads(response.text)[ 'sessionId'] # Todo: see if session_id variable is necesary self.request_url = self.host + 'session/' + self.session_id self.interactions = Interactions(self.host, self.session_id) self.elements = Elements(self.host, self.session_id) self.browser = Browser(self.request_url) def close_browser(self): ''' Closes the browser :return: X ''' self.browser.close_browser() def click(self, element): self.interactions.click(element) def write(self, element, text): self.interactions.write(element, text) def navigate(self, url): self.browser.navigate(url) def quit(self): requests.request('DELETE', self.host + 'session/' + self.session_id) self.webdriver_exec.terminate_driver() def maximize(self): self.browser.maximize() def minimize(self): self.browser.minimize() def fullscreen(self): self.browser.full_screen() def new_window(self): self.browser.new_window() def get_url(self): return self.browser.get_url() def get_title(self): return self.browser.get_title() def direction(self, direction): if direction.upper() == 'BACK': self.browser.back() else: self.browser.forward() def back(self): self.browser.back() def forward(self): self.browser.forward() def refresh(self): self.browser.refresh() # GET ELEMENT METHODS def get_element(self, locator, value): ''' Gets and element :param locator: The actual locator (property, id, xpath, link_text, css, partial_link_text,tag) :param value: The value to search the locator :return: an element. ''' element = self.elements.get_element(locator, value) if element == 'Error': print("The element was not located") self.quit() # Probably something will go here to mark the error quit() return element def get_element_by_property(self, prop, value): value = '//*[@' + prop + ' ="' + value + '"]' return self.elements.get_element('xpath', value) def get_element_by_id(self, value): value = '//*[@id ="' + value + '"]' return self.elements.get_element('xpath', value) def get_element_by_xpath(self, value): return self.elements.get_element('xpath', value) def get_element_by_link_text(self, value): return self.elements.get_element('link text', value) def get_element_by_css(self, value): return self.elements.get_element('css selector', value) def get_element_by_partial_link_text(self, value): return self.elements.get_element('partial link text', value) def get_element_by_tag(self, value): return self.elements.get_element('tag name', value)