def __init__(self, configure, debug, cb_status): self.configure = configure self.debug = debug self.config = Configuration(self.debug) self.xmltvfile = XMLTVFile(self.config) self.cb_status = cb_status self.reminders = Reminders(self.config) if os.path.exists(self.reminders.file): self.reminders = self.reminders.load() self.pw = ProgramWindow(self.xmltvfile) self.sd = SearchDialog(self.xmltvfile, self.reminders) self.pd = PreferencesDialog(self.config, self.xmltvfile, self.reminders, self.pw, self.sd) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) remote_object = self.__get_running_instance() if remote_object: print "OnTV is already running" exit() else: DBusService(self)
def __init__(self, program): gtk.Label.__init__(self) self.program = program self.reminders = Reminders() self.set_alignment(1.0, 0.5) self.show() self.update_id = gobject.timeout_add(TIMEOUT, self.update)
def __init__(self, chat_id=None, team=None): self.chat_id = chat_id self.team = team self.game = None self.updater = Updater(TOKEN) self.dp = self.updater.dispatcher # Jobs handler self.jobs = self.updater.job_queue #self.jobs.run_daily(self.get_game, datetime.time(hour=9, minute=0)) #self.jobs.run_repeating(self.check_score, interval=30) # Other handlers self.dp.add_handler( CommandHandler('remind', self.reminder, pass_args=True)) self.dp.add_handler(CommandHandler('uuu', self.uuu)) self.dp.add_handler(CommandHandler('opdedom', self.opdedom)) # Filters and filter handlers self.filters = MessageHandlers(self.dp) self.dp.add_handler( CommandHandler('remove', self.filters.remove, pass_args=True)) self.dp.add_handler( CommandHandler('filter', self.filters.new_filter, pass_args=True)) self.dp.add_handler( CommandHandler('houjebek', self.filters.disable_proactive_messages)) self.dp.add_handler( CommandHandler('wakkerworden', self.filters.enable_proactive_messages)) self.filters.load_filters() self.reminders = Reminders(self.jobs) self.updater.start_polling() self.updater.idle()
class ProgramTimeLeftBar(ProgramBar, gtk.Label): def __init__(self, program): gtk.Label.__init__(self) self.program = program self.reminders = Reminders() self.set_alignment(1.0, 0.5) self.show() self.update_id = gobject.timeout_add(TIMEOUT, self.update) def update(self): time_until_start = self.program.get_time_until_start() readable_time = self.get_readable_time(time_until_start) self.set_label(readable_time) if self.reminders.has_reminder(Reminder(self.program)): Notification(self.program, self.get_readable_time) return True
class UtregBot(object): def __init__(self, chat_id=None, team=None): self.chat_id = chat_id self.team = team self.game = None self.updater = Updater(TOKEN) self.dp = self.updater.dispatcher # Jobs handler self.jobs = self.updater.job_queue #self.jobs.run_daily(self.get_game, datetime.time(hour=9, minute=0)) #self.jobs.run_repeating(self.check_score, interval=30) # Other handlers self.dp.add_handler( CommandHandler('remind', self.reminder, pass_args=True)) self.dp.add_handler(CommandHandler('uuu', self.uuu)) self.dp.add_handler(CommandHandler('opdedom', self.opdedom)) # Filters and filter handlers self.filters = MessageHandlers(self.dp) self.dp.add_handler( CommandHandler('remove', self.filters.remove, pass_args=True)) self.dp.add_handler( CommandHandler('filter', self.filters.new_filter, pass_args=True)) self.dp.add_handler( CommandHandler('houjebek', self.filters.disable_proactive_messages)) self.dp.add_handler( CommandHandler('wakkerworden', self.filters.enable_proactive_messages)) self.filters.load_filters() self.reminders = Reminders(self.jobs) self.updater.start_polling() self.updater.idle() def reminder(self, bot, update, args): self.reminders.new_reminder(bot, update, args) def get_game(self, bot, update): self.game = Game(team=self.team) if self.game.check_game_today(): self.game.get_stats() message = self.game.notify_game_today() bot.send_message(chat_id=self.chat_id, text=message) def check_score(self, bot, update): if self.game and self.game.time: current_time = datetime.datetime.now() if self.game.time < current_time < self.game.time + datetime.timedelta( hours=3): message = self.game.get_score() if message: bot.send_message(chat_id=self.chat_id, text=message) @staticmethod def uuu(bot, update): message = 'UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU' message_chat(bot, update, message) @staticmethod def opdedom(bot, update): message = """ . Als ik boven op de dom sta kjik ik even naar benee dan zie ik het ouwe graggie het Vreeburg en Wijk C Ja dan sprink me hartjie ope ik ben trots wat daggie wat er is geen mooier plekkie as Utereg me stad as Utereg me stad """ message_chat(bot, update, message)
class OnTVCore: """Entry point for OnTV backend""" def __init__(self, configure, debug, cb_status): self.configure = configure self.debug = debug self.config = Configuration(self.debug) self.xmltvfile = XMLTVFile(self.config) self.cb_status = cb_status self.reminders = Reminders(self.config) if os.path.exists(self.reminders.file): self.reminders = self.reminders.load() self.pw = ProgramWindow(self.xmltvfile) self.sd = SearchDialog(self.xmltvfile, self.reminders) self.pd = PreferencesDialog(self.config, self.xmltvfile, self.reminders, self.pw, self.sd) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) remote_object = self.__get_running_instance() if remote_object: print "OnTV is already running" exit() else: DBusService(self) def update_listings(self): self.xmltvfile.download() def show_about_dialog(self): AboutDialog() def show_preferences_dialog(self): self.pd.show() def show_search_dialog(self): self.sd.show() def toggle_program_window(self): visible = self.pw.is_visible() if visible: self.pw.hide_window() else: self.pw.show_window(self.window_position) return visible def __get_running_instance(self): session_bus = dbus.SessionBus() dbus_object = session_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus') services = dbus_iface.ListNames() if "org.gnome.OnTV" in services: return session_bus.get_object("org.gnome.OnTV","/DBusService") return False def run(self): if self.configure or self.config.grabber_command == '': xmltv_assistant = XMLTVAssistant(self.config, self.xmltvfile) xmltv_assistant.show() else: self.xmltvfile.connect("downloading", self.__xmltvfile_activity, _("Downloading TV Listings...")) self.xmltvfile.connect("downloading-done", self.__xmltvfile_downloading_done) self.xmltvfile.connect("sorting", self.__xmltvfile_activity, _("Sorting TV Listings...")) self.xmltvfile.connect("sorting-done", self.__xmltvfile_sorting_done) self.xmltvfile.connect("loading", self.__xmltvfile_activity, _("Loading TV Listings...")) self.xmltvfile.connect("loading-done", self.__xmltvfile_loading_done) self.xmltvfile.load() def __xmltvfile_activity(self, xmltvfile, activity): self.cb_status(activity) def __xmltvfile_downloading_done(self, xmltvfile, pid, condition): self.cb_status("") self.xmltvfile.sort() def __xmltvfile_sorting_done(self, xmltvfile, pid, condition): self.cb_status("") self.xmltvfile.load() def __xmltvfile_loading_done(self, xmltvfile, listings): self.cb_status("") def get_program_window_size(self): return self.pw.get_window_size() def set_program_window_position(self, window_position): self.window_position = window_position
def add_reminder(self): """ Method to add the reminder to the list. """ if self.ui.line_edit.text() == '': error_msg = qtw.QMessageBox() error_msg.setWindowTitle('Error') error_msg.setIcon(qtw.QMessageBox.Critical) error_msg.setText('Title field is empty!') error_msg.setStandardButtons(qtw.QMessageBox.Ok) error_msg.exec_() elif self.ui.text_edit.toPlainText() == '': error_msg = qtw.QMessageBox() error_msg.setWindowTitle('Error') error_msg.setIcon(qtw.QMessageBox.Critical) error_msg.setText('Content field is empty!') error_msg.setStandardButtons(qtw.QMessageBox.Ok) error_msg.exec_() else: r_date, r_month, r_year = self.ui.date_edit.date().day( ), self.ui.date_edit.date().month(), self.ui.date_edit.date().year( ) #Getting the date of reminder. date_format = f'{str(r_date)}-{str(r_month)}-{str(r_year)}' r_hour, r_minutes = self.ui.time_edit.time().hour( ), self.ui.time_edit.time().minute( ) #Getting the time of reminder. if r_hour in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: r_hour = '0' + str(r_hour) if r_minutes in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: r_minutes = '0' + str(r_minutes) time_format = f'{str(r_hour)}:{str(r_minutes)}' msg_title = self.ui.line_edit.text( ) #Getting the title of the remainder. msg_content = self.ui.text_edit.toPlainText( ) #Getting the content of the reminder. if self.check_duplicate_title(msg_title): error_msg_dup = qtw.QMessageBox() error_msg_dup.setWindowTitle('Error') error_msg_dup.setIcon(qtw.QMessageBox.Critical) error_msg_dup.setText( 'Duplicate title exists. Please try a different one.') error_msg_dup.setStandardButtons(qtw.QMessageBox.Ok) error_msg_dup.exec_() else: reminder = Reminders(date_format, time_format, msg_title, msg_content) self.list_of_reminders.append( reminder.get_tuple() ) #Adding a tuple so that heap sorts the reminders based on date and time. heapq.heapify( self.list_of_reminders ) #Using heapq for maintaining the order of the reminders based on date and time. self.ui.list_widget.clear() #Displaying on the list in sorted order. self.ui.list_widget.addItem('Reminder Titles:') for item in self.list_of_reminders: self.ui.list_widget.addItem(item[2] + ' on ' + item[0] + ' @' + item[1]) self.ui.line_edit.clear() self.ui.text_edit.clear() self.ui.time_edit.setMinimumTime(QtCore.QTime.currentTime()) self.ui.date_edit.setMinimumDate(QtCore.QDate.currentDate())
#!/usr/bin/python from slacker import Slacker from reminders import Reminders import config def make_mentions(users): mentions = '' for user in users : if user in config.user_map and config.user_map[user] not in config.user_blacklist : mentions += '@' + config.user_map[user] + ' ' return mentions # Start the app reminders = Reminders(config.gh_access_token, config.org_repo) slack = Slacker(config.slack_token) for reminder in reminders.get_reminders(): slack.chat.post_message( '#' + config.channel.replace('#', ''), '<%s|[PR #%d - %s]> needs attention %s' % ( reminder['pr_link'], reminder['number'], reminder['title'], make_mentions(reminder['users_to_remind']) ), link_names=1 )
raise ExposableException('response too long') if (len(buffer) + len(line)) < DISCORD_MESSAGE_LENGTH_LIMIT: buffer += line else: result.append(buffer) buffer = line if len(buffer) > 0: result.append(buffer) return result if __name__ == "__main__": discord_client = discord.Client() global_config = readConfig(CONFIG_FILE_PATH) global_config.wotv_bot_config.discord_client = discord_client global_config.wotv_bot_config.reminders = Reminders(REMINDERS_DB_PATH) global_config.wotv_bot_config.spreadsheet_app = WorksheetUtils.getSpreadsheetsAppClient( ) wotv_bot = WotvBot(global_config.wotv_bot_config) logger = logging.getLogger('discord') logger.setLevel(logging.INFO) # logger.setLevel(logging.DEBUG) # handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) logger.addHandler(handler) @discord_client.event async def on_ready():