class FaceBookPost: @staticmethod def get_aut_token(app_id, app_secred): return utils.get_application_access_token(app_id, app_secred) def __init__(self, page_id, app_id, app_secret): self.cfg = {"page_id": page_id, "access_token": "TODO"} self.mylogging = MyLogging() def facebook_post(self, message): api = self.get_api() self.mylogging.log().info("Post message %s" % message) status = api.put_wall_post(message) self.mylogging.log().info(status) def get_api(self): graph = facebook.GraphAPI(self.cfg['access_token']) resp = graph.get_object('me/accounts') page_access_token = None for page in resp['data']: if page['id'] == self.cfg['page_id']: page_access_token = page['access_token'] graph = facebook.GraphAPI(page_access_token) return graph
class AddPersonToChat: def set_up(self): chrome_driver_path = get_driver_path() + '\\chromedriver.exe' self.driver = webdriver.Chrome(chrome_driver_path) self.driver.implicitly_wait(2) self.skype_bot = SkypeBot(self.driver) def __init__(self): self.mylogging = MyLogging() self.set_up() def login(self, authentication): self.skype_bot.login(authentication) def add_person_to_chat(self, names, chat="Szopy Reaktywacja!"): self.skype_bot.select("Echo") self.skype_bot.select(chat) self.skype_bot.add_person_button_click() actions = ActionChains(self.driver) for name in names: self.mylogging.log().info("Try add %s to chat %s" % (name, chat)) actions.send_keys(name) actions.perform() self.skype_bot.search_item_click(name) def tear_down(self): self.driver.quit()
class SkypeApiAdapter: def __init__(self, skype_api, groups): self.my_logging = MyLogging() self.skype_api = skype_api self.groups = groups def login(self, login, passwod): self.skype_api.login(login, passwod) def send_message(self, message): self.my_logging.log().info(message) self.skype_api.set_chats(self.groups) self.skype_api.send_message(message)
class SkypeBotAdapter: def __init__(self, skype_bot, groups): self.my_logging = MyLogging() self.skype_bot = skype_bot self.groups = groups def login(self, login, passwod): self.skype_bot.login(login, passwod) def send_message(self, message): self.my_logging.log().info(message) self.skype_bot.set_chats(self.groups) self.skype_bot.send_message_to_selected(message)
def before_feature(context, feature): create_dir(logs_path) context.feature_logging = MyLogging() context.log_feature_file = logs_path + "\\%s_Log.log" % feature.name context.feature_logging.add_log_file(context.log_feature_file) context.feature_logging.log().info("Start Feature: " + feature.name)
class ApiAdapter: def __init__(self, api): self.api = api self.my_logging = MyLogging() def login(self, login, passw): self.api.login(login, passw) def sent_messages(self, messages): self.my_logging.log().info(messages) for message in messages: self.api.send_message(message) def save_history(self, message, file): self.my_logging.save_history(message, file) def logout(self): self.api.logout()
class SongOfTheDay: def __init__(self, page_id, app_id, app_secret): self.set_up(page_id, app_id, app_secret) self.mylogging = MyLogging() def sent_song(self, songs_urls): for songURL in songs_urls: self.mylogging.log().info(songURL) self.face_bot.facebook_post(songURL) def set_up(self, page_id, app_id, app_secret): update_songs_distribution() chrome_driver_path = get_driver_path() + '\\chromedriver.exe' self.driver = webdriver.Chrome(chrome_driver_path) self.driver.implicitly_wait(2) self.face_bot = FaceBookPost(page_id, app_id, app_secret) def tear_down(self): self.driver.quit()
class TinderAdapter: def __init__(self, name, receivers, driver, tiderBot): self.tm = tiderBot self.name = name self.mylogging = MyLogging() self.receivers = receivers self.driver = driver def login(self, login, passw): token = get_access_token(login, passw) id = get_facebook_ID(self.driver, self.name) self.tm.logIn(id, token) def send_message(self, message): for match in self.tm.get_matches(): if match.user.name in self.receivers: self.mylogging.log("Send message to: %s " % match.user.name) match.message("[ Auto song for: %s :D ]" % match.user.name) match.message(message)
def before_scenario(context, scenario): context.scenario_logging = MyLogging() context.scenario_name = scenario.name.replace(" ", "_") context.time_stump = str(time.strftime('%Y-%m-%d_%H_%M_%S')) context.logs_dir_name = logs_path + "\\" + context.scenario_name + "_" + context.time_stump create_dir(context, context.logs_dir_name) context.log_file = context.logs_dir_name + "\\%s_Log_%s.log" % ( context.scenario_name, context.time_stump) context.scenario_logging.add_log_file(context.log_file) set_up(context, "TODO") context.scenario_logging.log().info("Scenario started: " + scenario.name)
def func(*args, **kwargs): my_logging = MyLogging() try: return f(*args, **kwargs) except Exception as err: my_logging.log().error(str(err)) my_logging.log().error(sys.exc_info()) if rize: raise RuntimeError
def func(self): my_logging = MyLogging() try: res = f(self) my_logging.log_result(f.__name__, "Pass") return res except AssertionError: my_logging.log_result(f.__name__, "Fail") self.fail("fail")
def set_up(context): context.my_loggin = MyLogging() remote = False if remote: # self.driver = WebDriver("http://localhost:4444/wd/hub", "chrome", "ANY") # context.driver = WebDriver("http://192.168.99.100:5000", DesiredCapabilities.CHROME) # context.driver = WebDriver(command_executor="http://192.168.99.100:5000/wd/hub", desired_capabilities=DesiredCapabilities.CHROME,proxy=None) # options = webdriver.ChromeOptions context.driver = WebDriver( command_executor="http://192.168.99.100:5000/wd/hub", desired_capabilities=CHROME) # context.driver = webdriver.Remote( # command_executor='http://192.168.99.100:5000/wd/hub', # desired_capabilities={'browserName': 'chrome', 'javascriptEnabled': True}) # don't work becouse grid bug else: chrome_driver_path = get_driver_path() + '\\chromedriver.exe' context.driver = webdriver.Chrome(chrome_driver_path) context.driver.get(SERVER) context.calculator = CalculatorElements(context.driver) # context.driver.maximize_window() context.driver.implicitly_wait(10)
def __init__(self, name, receivers, driver, tiderBot): self.tm = tiderBot self.name = name self.mylogging = MyLogging() self.receivers = receivers self.driver = driver
def __init__(self, skype_api, groups): self.my_logging = MyLogging() self.skype_api = skype_api self.groups = groups
def __init__(self, api): self.api = api self.my_logging = MyLogging()
def __init__(self, skype_bot, groups): self.my_logging = MyLogging() self.skype_bot = skype_bot self.groups = groups
import os import time import speedtest from Utils.decorators import log_exception from Utils.utils import MyLogging mylogging = MyLogging() @log_exception() def test_speed(log_=True): servers = [] s = speedtest.Speedtest() s.get_servers(servers) s.get_best_server() s.download() s.upload() res = s.results.dict() if log_: mylogging.log().info(res) return res if __name__ == "__main__": with open("E:\Google_drive\statistics\speed.csv", 'a') as f: time_stump = time.strftime('%Y-%m-%d %H:%M:%S') res = str(test_speed()) f.write("%s, %s\n" % (time_stump, res)) mylogging.log( os.path.abspath( os.path.join(os.path.dirname(__file__), '..', 'Utils')) +
def __init__(self, page_id, app_id, app_secret): self.set_up(page_id, app_id, app_secret) self.mylogging = MyLogging()
def before_feature(context, feature): context.mylogging = MyLogging() context.logFeatureFile = get_screen_path() + "\\Log.txt" context.mylogging.log(context.logFeatureFile).info("Start Feature : " + feature.name)
def __init__(self, page_id, app_id, app_secret): self.cfg = {"page_id": page_id, "access_token": "TODO"} self.mylogging = MyLogging()
def __init__(self, user_name, client_id, client_secret, redirect_uri): self.mylogging = MyLogging() self.user_name = user_name token = self.get_token(user_name, client_id, client_secret, redirect_uri) self.sp = spotipy.Spotify(auth=token)
import time from threading import Thread from Utils.utils import MyLogging mylogging = MyLogging() class FaceThreadMonitor: def __init__(self, face_bot, thread_ID): self.face_bot = face_bot self.thread_ID = thread_ID def monitor_thread(self, phrases, queue): for message in self.face_bot.get_messages(self.thread_ID): if str(message.text) in phrases: msg = str((self.thread_ID, message.timestamp)) queue.put(msg) def monitor(self, phrase, queue): while 1: self.monitor_thread(phrase, queue) time.sleep(300) def start_monitor(phraze, face_thread_monitor_list, queue): threads = [] for ftm in face_thread_monitor_list: try: thread = Thread(target=ftm.monitor, args=(phraze, queue)) threads.append(thread)
def before_scenario(context, scenario): context.scenario_logging = MyLogging() context.scenario_name = scenario.name.replace(" ", "_") context.time_stump = str(time.strftime('%Y-%m-%d_%H_%M_%S'))
import re import requests from Utils.utils import MyLogging from bs4 import BeautifulSoup logger = MyLogging() def get_youtube_url(query): logger.log().info(query) response = requests.get("https://www.youtube.com/results?search_query=%s" % query).text soup = BeautifulSoup(response, "html.parser") urls = soup.find_all(href=True) links = [re.search('.*href="/watch.*', str(url)) for url in urls] links = [link.group(0) for link in links if link is not None] links = [re.search('href="/watch.*"', link).group(0) for link in links] return "https://www.youtube.com/%s" % links[0][links[0].index("watch"): links[0].index('">')] if __name__ == "__main__": print(get_youtube_url("Test"))
def __init__(self): self.mylogging = MyLogging() self.set_up()
class SpotifyApi: def __init__(self, user_name, client_id, client_secret, redirect_uri): self.mylogging = MyLogging() self.user_name = user_name token = self.get_token(user_name, client_id, client_secret, redirect_uri) self.sp = spotipy.Spotify(auth=token) def get_token(self, user_name, client_id, client_secret, redirect_uri): """https://developer.spotify.com/web-api/using-scopes/""" scope = 'playlist-modify-public' token = util.prompt_for_user_token(username=user_name, scope=scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri) if token: return token else: self.mylogging.log().info("Can't get token for: %s" % user_name) def get_playlists(self): return self.sp.current_user_playlists() def get_tracks_ids(self, tracks_list): id_map = map(self.sp.search, tracks_list) ids = [] for track in list(id_map): try: ids.append(track['tracks']['items'][0]['id']) except Exception as ex: print(ex) continue return ids def save_tracks_ides_to_file(self, tracks_list, file_name): create_file_if_not_exist(file_name) with open(file_name, "a") as f1: for line in self.get_tracks_ids(tracks_list): f1.write(line + "\n") f1.flush() def create_playlist( self, name, public=True, ): user_id = sa.sp.current_user()['id'] return self.sp.user_playlist_create(user_id, name, public) def add_tracks(self, play_list_id, tracks_ides): user_id = sa.sp.current_user()['id'] try: self.sp.user_playlist_add_tracks(user=user_id, playlist_id=play_list_id, tracks=tracks_ides) except Exception as ex: print(ex) pass def get_song_uri(self, song_id): return self.sp.track(song_id).strip()