def set_function(bot: Bot, update: Update): print(TAG(), "called set: ", update.message) chat_id = update.message.chat_id args = update.message.text.split(" ") if len(args) < 2: bot.send_message(chat_id=chat_id, text="Invalid message. Command pattern is:") bot.send_message(chat_id=chat_id, text="/set name URL [CSS SELECTOR]") return name, url = args[1], args[2] watcher = Watcher(name, url, update) if len(args) > 3: watcher.selector = " ".join(args[3:]) watcher.type = Selector.CSS else: watcher.type = Selector.NONE ok = watcher_manager.add_watcher(chat_id, watcher) if ok: bot.send_message( chat_id=chat_id, text="Notifier {0} correctly created! (SELECTOR: '{1}' ({2}))". format(watcher.name, watcher.selector, watcher.type)) print("{0}: watcher {1} created.".format(chat_id, name)) else: bot.send_message( chat_id=chat_id, text="Notifier {0} already exists. Please delete it".format(name)) flush()
def __init__(self, api): self.quotes = [] self.api = api self.watcher = Watcher(api) self.images = None self.init_paths() self.load_quotes() self.load_image_store()
def __init__(self, wyman_file): self.file_path = wyman_file self.watcher_obj = None self.poster_obj = None self.twitter_user = None self.web_hook = None self.text_enabled = True self.images_enabled = True # default is 10 minutes (600 seconds) self.check_delay = 600 with open(self.file_path, "r") as opened: try: self.config = json.loads(opened.read()) except json.JSONDecodeError: print("Invalid configuration file [{}]!", self.file_path) return if is_valid_user(self.config["twitter_handle"]): self.twitter_user = self.config["twitter_handle"] if is_valid_web_hook(self.config["webhook"]): self.web_hook = self.config["webhook"] self.watcher_obj = Watcher(self.twitter_user) self.poster_obj = Poster(self.watcher_obj, self.web_hook) if str(self.config["text_enabled"]).lower() == "false": self.poster_obj.disable_text() if str(self.config["images_enabled"]).lower() == "false": self.poster_obj.disable_images() if str(self.config["links_enabled"]).lower() == "false": self.poster_obj.disable_links() try: self.check_delay = int(self.config["check_delay"]) except ValueError: print( "check_delay is not a number!\ndefaulting to 10 minute delay.")
def Main(): if len(sys.argv) <= 1: print("Argument required: create, watch, buy, sell, stats") else: if sys.argv[1] == 'create': if len(sys.argv) < 3: print("Invalid arguments. `python main.py create 5000`") else: watcher = Watcher(filename='data/portfolio', hyperparameters=hyperparameters) watcher.create(balance=float(sys.argv[2])) elif sys.argv[1] == 'watch': watcher = Watcher(filename='data/portfolio', hyperparameters=hyperparameters) watcher.start() elif sys.argv[1] == 'buy': # main.py buy 20 AMD 81.26 if len(sys.argv) < 5: print("Invalid arguments. `python main.py buy 20 AMD 81.26`") else: executor = Executor(filename='data/portfolio', hyperparameters=hyperparameters) print( executor.buy(symbol=sys.argv[3], count=int(sys.argv[2]), value=float(sys.argv[4]))) elif sys.argv[1] == 'sell': # main.py sell 20 AMD 81.26 if len(sys.argv) < 5: print("Invalid arguments. `python main.py sell 20 AMD 81.26`") else: executor = Executor(filename='data/portfolio', hyperparameters=hyperparameters) print( executor.sell(symbol=sys.argv[3], count=int(sys.argv[2]), value=float(sys.argv[4]))) elif sys.argv[1] == 'stats': watcher = Watcher(filename='data/portfolio', hyperparameters=hyperparameters) watcher.stats() elif sys.argv[1] == 'sim': from Sim import Sim from Analysis import Analysis sim = Sim(period='3y', timedelay=100, window=100, timestep=1, budget=5000, stockPicks=5, avoidDowntrends=True, sellAllOnCrash=False, **hyperparameters) stats = sim.run() analysis = Analysis(stats=stats, positions=sim.portfolio.holdings, prices=sim.downloader.prices) analysis.chart('data/best_optimized_3y.png') output, advanced_stats = analysis.positionStats() print(output) g = sim.portfolio.holdings.copy().groupby('label').sum() g['profits_pct'] = (g['current_price'] - g['purchase_price'] ) / g['purchase_price'] * 100 print(g) elif sys.argv[1] == 'check': watcher = Watcher(filename='data/portfolio', hyperparameters=hyperparameters) watcher.check(sys.argv[2]) else: print("Unknown command")
import proxy from Watcher import Watcher import time from random import randint if __name__ == "__main__": while True: try: watchers_count = int(input("Number of bots: ")) if watchers_count < 1: raise ValueError break except ValueError as e: print("Somár, číslo veď...") for _ in range(watchers_count): proxy.switchIP() watcher = Watcher() watcher.start() time.sleep(randint(5, 10))
from Watcher import Watcher import os downloads_path = os.path.expanduser('~/Downloads') # desktop_path = os.path.expanduser('~/Desktop') # enable watcher watcher = Watcher(downloads_path) watcher.run()