def monitoring_one(self, firm_code, firm_name, start_price, stop_ratio, win_ratio, buy_date, num, flags): price_data = CrawlingFirmPriceData('day', 1) try: firms = price_data.crawling_type_a(firm_code,firm_name) except requests.exceptions.Timeout: time.sleep(60) firms = price_data.crawling_type_a(firm_code,firm_name) stop_price = int(self.stop_loss_price(start_price, stop_ratio)) win_price = int(self.win_price(start_price, win_ratio)) close = int(firms.loc[0, 'close']) stop_ratio = round(close / stop_price, 2) win_ratio = round(close / win_price, 2) count_day = buy_date print('{0} monitoring {1} win:{2}/{3}-{4}, stop:{5}/{6}-{7}, buy_date:{8}, {9}'.format( num, firm_code, close, win_price, win_ratio, close, stop_price, stop_ratio, count_day, firm_name)) print('-'*95) if stop_price >= close: Alert().stop_alert(firms) flags[num] = 1 return flags if win_price <= close: Alert().win_alert(firms) flags[num] = 1 return flags return flags
def __init__(self): Clock.__init__(self, _("Timer")) self.state = Timer.State.STOPPED self.timeout_id = 0 self.notebook = Gtk.Notebook() self.notebook.set_show_tabs(False) self.notebook.set_show_border(False) self.add(self.notebook) # force the time label and the spinner to the same size size_group = Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL); self.setup_screen = TimerSetupScreen(self, size_group) self.notebook.append_page(self.setup_screen, None) self.timer_screen = TimerScreen(self, size_group) self.notebook.append_page(self.timer_screen, None) self.alert = Alert("complete", "Ta Da !", self._on_notification_activated)
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import config CFG = config.getConfig() alert_logfile = "/var/log/druid/admin_alerts.log" WARNING_DAYS = [0, 1, 3, 5, 7, 14, 30] log = logging.getLogger('retire_nodes') log.setLevel(logging.INFO) fh = logging.FileHandler(alert_logfile) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) log.addHandler(fh) alert = Alert(sys.argv[1:9]) log.debug("Events=%d Name='%s' Trigger='%s' URL='%s' Raw results='%s'" % (alert.numevents, alert.search_name, alert.trigger_reason, alert.saved_search_url, alert.raw_results)) retire = [x for x in alert.events if x['retire'] == 1] expire = [x for x in alert.events if x['retire'] == 0] # First, lets send warnings for the users about node expirations contacts = list( set([ x['CONTACT'].lower() for x in expire if int(x['days_to_expire']) in WARNING_DAYS ]))
import config CFG = config.getConfig() alert_logfile = "/var/log/druid/alerts.log" FEED_RSS = "/var/www/html/s/alert_rss.xml" RSS_MAX_AGE = timedelta(hours=24) log = logging.getLogger('alerts') log.setLevel(logging.INFO) fh = logging.FileHandler(alert_logfile) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) log.addHandler(fh) alert = Alert(sys.argv[1:9]) log.debug("Events=%d Search='%s' Trigger='%s' URL='%s' Raw results='%s'" % (alert.numevents, alert.fullsearch, alert.trigger_reason, alert.saved_search_url, alert.raw_results)) log.debug('%s' % pprint.pformat(alert.__dict__)) if os.path.isfile(FEED_RSS): # Read the current RSS feed feed_rss = open(FEED_RSS, "r+") fcntl.flock(feed_rss, fcntl.LOCK_EX) f = feedparser.parse(feed_rss.read()) feed = Feed() feed.feed['title'] = f['feed']['title'] feed.feed['link'] = f['feed']['link']
class Timer(Clock): LABEL_MARKUP = "<span font_desc=\"64.0\">%02i:%02i:%02i</span>" BUTTON_MARKUP = "<span font_desc=\"18.0\">% s</span>" class State: STOPPED = 0 RUNNING = 1 PAUSED = 2 def __init__(self): Clock.__init__(self, _("Timer")) self.state = Timer.State.STOPPED self.timeout_id = 0 self.notebook = Gtk.Notebook() self.notebook.set_show_tabs(False) self.notebook.set_show_border(False) self.add(self.notebook) # force the time label and the spinner to the same size size_group = Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL); self.setup_screen = TimerSetupScreen(self, size_group) self.notebook.append_page(self.setup_screen, None) self.timer_screen = TimerScreen(self, size_group) self.notebook.append_page(self.timer_screen, None) self.alert = Alert("complete", "Ta Da !", self._on_notification_activated) def _on_notification_activated(self, notif, action, data): win = self.get_toplevel() win.show_clock(self) def show_setup_screen(self, reset): self.notebook.set_current_page(0) if reset: self.setup_screen.set_values(0, 0, 0) def show_timer_screen(self): self.notebook.set_current_page(1) def _add_timeout(self): self.timeout_id = GObject.timeout_add(250, self.count) def _remove_timeout(self): if self.timeout_id != 0: GObject.source_remove(self.timeout_id) self.timeout_id = 0 def start(self): if self.state == Timer.State.STOPPED and self.timeout_id == 0: h, m, s = self.setup_screen.get_values() self.timer_screen.set_time(h, m, s) self.duration = (h * 60 * 60) + (m * 60) + s self.deadline = time.time() + self.duration self.state = Timer.State.RUNNING self._add_timeout() self.show_timer_screen() def reset(self): self.state = Timer.State.STOPPED self._remove_timeout() self.show_setup_screen(True) def pause(self): self.duration = self.deadline - time.time() self.state = Timer.State.PAUSED self._remove_timeout() def cont(self): self.deadline = time.time() + self.duration self.state = Timer.State.RUNNING self._add_timeout() def count(self): t = time.time() if t >= self.deadline: self.alert.show() self.state = Timer.State.STOPPED self._remove_timeout() self.timer_screen.set_time(0, 0, 0) self.show_setup_screen(False) return False else: r = self.deadline - t m, s = divmod(r, 60) h, m = divmod(m, 60) self.timer_screen.set_time(h, m, s) return True