Something that some of you may find handy - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Something that some of you may find handy (/thread-9670.html) |
Something that some of you may find handy - CharlieGallie - Apr-22-2018 I didn't really know what group to post this is, hopefully this is the best one. I made this thing for everyone to use how ever you want. import random class colour: #Common colours #green light_green = (0, 252, 0) dark_green = (0, 58, 18) green = (5, 191, 24) #blue light_blue = (2, 162, 255) dark_blue = (0, 46, 73) blue = (5, 123, 191) #red light_red = (249, 2, 23) dark_red = (104, 1, 9) red = (201, 4, 4) brown = (60, 50, 0) orange = (255, 150, 0) #pink light_pink = (245, 107, 255) dark_pink = (85, 1, 91) pink = (182, 25, 193) purple = (85, 1, 91) #yellow yellow = (225, 225, 0) #Less Common Colours turquoise = (0, 255, 178) white = (255, 255, 255) black = (0, 0, 0) light_grey = (200, 200, 200) silver = (150, 150, 150) fog = (20, 20, 20) dim_grey = (50, 50, 50) mist = (120, 120, 120) sky = (209, 226, 255) dark_grey = (127, 127, 127) cyan = (81, 210, 239) magenta = (188, 5, 136) sarcoline = (155, 163, 160) liver = (76, 76, 76) lilac = (175, 140, 175) amber = (226, 168, 31) maroon = (109, 30, 26) #random colour generator randomCol = (0, 0, 0) col1 = random.randint(0, 255) col2 = random.randint(0, 255) col3 = random.randint(0, 255) randomCol = (col1,col2,col3)I think you'll be able to understand how to use it. RE: Something that some of you may find handy - snippsat - Apr-23-2018 (Apr-22-2018, 11:48 PM)CharlieGallie Wrote: I made this thing for everyone to use how ever you want.Code dos nothing,RGB colors setup is okay but... Quote:I think you'll be able to understand how to use it.Maybe,here one solution that take it a lot future # color.py import random import time from selenium import webdriver from selenium.webdriver.common.keys import Keys class CommonColor: # green light_green = (0, 252, 0) dark_green = (0, 58, 18) green = (5, 191, 24) # blue light_blue = (2, 162, 255) dark_blue = (0, 46, 73) blue = (5, 123, 191) # red light_red = (249, 2, 23) dark_red = (104, 1, 9) red = (201, 4, 4) brown = (60, 50, 0) orange = (255, 150, 0) # pink light_pink = (245, 107, 255) dark_pink = (85, 1, 91) pink = (182, 25, 193) purple = (85, 1, 91) # yellow yellow = (225, 225, 0) class LessCommonColor: turquoise = (0, 255, 178) white = (255, 255, 255) black = (0, 0, 0) light_grey = (200, 200, 200) silver = (150, 150, 150) fog = (20, 20, 20) dim_grey = (50, 50, 50) mist = (120, 120, 120) sky = (209, 226, 255) dark_grey = (127, 127, 127) cyan = (81, 210, 239) magenta = (188, 5, 136) sarcoline = (155, 163, 160) liver = (76, 76, 76) lilac = (175, 140, 175) amber = (226, 168, 31) maroon = (109, 30, 26) def random_color(): random_col = (0, 0, 0) col1 = random.randint(0, 255) col2 = random.randint(0, 255) col3 = random.randint(0, 255) random_col = (col1, col2, col3) return random_col def show_in_browser(c_rgb): ''' Open Chrome and show RGB value For this function to work most setup selenium with chromedriver ''' browser = webdriver.Chrome() url = 'http://www.color-hex.com/' browser.get(url) color = browser.find_elements_by_css_selector('#colorvalue')[0] color.send_keys(c_rgb) color.send_keys(Keys.RETURN) time.sleep(10) #seconds browser.quit() def menu(): while True: print('\n(1) Choice a random common color') print("(2) Choice a random color that's less common") print('(3) Just a random color') print('(Q) Quit\n') choice = input('Enter your choice: ').lower() if choice == '1': col = CommonColor() lst = [i for i in dir(col) if '__' not in i] rbg = random.choice(lst) c_rgb = getattr(col, rbg) c_rgb = f'rgb{c_rgb}' print('-----') print(c_rgb) print('-----') b_choice = input('Show in Browser yes | no: '.lower()) if b_choice == 'yes': show_in_browser(c_rgb) else: menu() elif choice == '2': col = LessCommonColor() lst = [i for i in dir(col) if '__' not in i] rbg = random.choice(lst) c_rgb = getattr(col, rbg) c_rgb = f'rgb{c_rgb}' print('-----') print(c_rgb) print('-----') b_choice = input('Show in Browser yes | no: '.lower()) if b_choice == 'yes': show_in_browser(c_rgb) else: menu() elif choice == '3': print('-----') c_rgb = random_color() c_rgb = f'rgb{c_rgb}' print(c_rgb) print('-----') b_choice = input('Show in Browser yes | no: '.lower()) if b_choice == 'yes': c_rgb = f'rgb{c_rgb}' show_in_browser(c_rgb) else: menu() elif choice == 'q': return else: print(f'Not a correct choice: <{choice}>,try again') if __name__ == '__main__': menu() If Selenium is setup: |