def parse_comment(body, trigger, comment_created): time_string = utils.find_reminder_time(body, trigger) time_string = time_string.strip() if time_string is not None else None target_date = None if time_string is not None: target_date = utils.parse_time(time_string, comment_created, None) return time_string, target_date
def process_remind_me(message, reddit, database, recurring): log.info("Processing RemindMe message") trigger = static.TRIGGER_RECURRING_LOWER if recurring else static.TRIGGER_LOWER time = utils.find_reminder_time(message.body, trigger) message_text = utils.find_reminder_message(message.body, trigger) reminder, result_message = Reminder.build_reminder( source=utils.message_link(message.id), message=message_text, user=database.get_or_add_user(message.author.name), requested_date=utils.datetime_from_timestamp(message.created_utc), time_string=time, recurring=recurring) if reminder is None: log.debug("Reminder not valid, returning") return [result_message], False database.add_reminder(reminder) database.commit() log.info( f"Reminder created: {reminder.id} : {utils.get_datetime_string(reminder.target_date)}" ) bldr = reminder.render_message_confirmation( result_message, pushshift_minutes=reddit.get_effective_pushshift_lag()) return [''.join(bldr)], True
def parse_comment(comment, database, count_string): if comment['author'] == static.ACCOUNT_NAME: log.debug("Comment is from remindmebot") return None log.info( f"{count_string}: Processing comment {comment['id']} from u/{comment['author']}" ) body = comment['body'].lower() if f"{static.TRIGGER_LOWER}!" not in body and f"!{static.TRIGGER_LOWER}" not in body: log.debug("Command not in comment") return None time = utils.find_reminder_time(comment['body']) message_text = utils.find_reminder_message(comment['body']) reminder = Reminder( source=utils.reddit_link(comment['permalink']), message=message_text, user=comment['author'], requested_date=utils.datetime_from_timestamp(comment['created_utc']), time_string=time, timezone=database.get_settings(comment['author']).timezone) if not reminder.valid: return None if not database.save_reminder(reminder): reminder.result_message = "Something went wrong saving the reminder" reminder.valid = False log.warning(reminder.result_message) return reminder
def process_remind_me(message, database): log.info("Processing RemindMe message") time = utils.find_reminder_time(message.body) message_text = utils.find_reminder_message(message.body) reminder = Reminder( source=utils.message_link(message.id), message=message_text, user=message.author.name, requested_date=utils.datetime_from_timestamp(message.created_utc), time_string=time, timezone=database.get_settings(message.author.name).timezone) if not reminder.valid: log.debug("Reminder not valid, returning") return [reminder.result_message] if not database.save_reminder(reminder): log.info("Something went wrong saving the reminder") return ["Something went wrong saving the reminder"] log.info( f"Reminder created: {reminder.db_id} : {utils.get_datetime_string(reminder.target_date)}" ) return reminder.render_message_confirmation()
def parse_comment(comment, database, count_string, reddit): if comment['author'] == static.ACCOUNT_NAME: log.debug("Comment is from remindmebot") return None, None if comment['author'] in static.BLACKLISTED_ACCOUNTS: log.debug("Comment is from a blacklisted account") return None, None log.info( f"{count_string}: Processing comment {comment['id']} from u/{comment['author']}" ) body = comment['body'].lower().strip() recurring = False cakeday = False allow_default = True if trigger_in_text(body, static.TRIGGER_RECURRING_LOWER): log.debug("Recurring reminder comment") recurring = True trigger = static.TRIGGER_RECURRING_LOWER elif trigger_in_text(body, static.TRIGGER_LOWER): log.debug("Regular comment") trigger = static.TRIGGER_LOWER elif trigger_start_of_line(body, static.TRIGGER_CAKEDAY_LOWER): log.debug("Cakeday comment") cakeday = True recurring = True trigger = static.TRIGGER_CAKEDAY_LOWER elif trigger_start_of_line(body, static.TRIGGER_SPLIT_LOWER): log.debug("Regular split comment") trigger = static.TRIGGER_SPLIT_LOWER allow_default = False else: log.debug("Command not in comment") return None, None target_date = None if cakeday: if database.user_has_cakeday_reminder(comment['author']): log.info("Cakeday already exists") return None, None target_date = utils.get_next_anniversary( reddit.get_user_creation_date(comment['author'])) message_text = static.CAKEDAY_MESSAGE time = "1 year" else: time = utils.find_reminder_time(comment['body'], trigger) message_text = utils.find_reminder_message(comment['body'], trigger) reminder, result_message = Reminder.build_reminder( source=utils.reddit_link(comment['permalink']), message=message_text, user=database.get_or_add_user(comment['author']), requested_date=utils.datetime_from_timestamp(comment['created_utc']), time_string=time, recurring=recurring, target_date=target_date, allow_default=allow_default) if reminder is None: return None, None if cakeday: counters.replies.labels(source='comment', type='cake').inc() elif recurring: counters.replies.labels(source='comment', type='repeat').inc() elif not allow_default: counters.replies.labels(source='comment', type='split').inc() else: counters.replies.labels(source='comment', type='single').inc() database.add_reminder(reminder) reminder.user.recurring_sent = 0 return reminder, result_message
log.info(f"Current time: {utils.get_datetime_string(current)}") while True: newUrl = url + str(previousEpoch) json = requests.get( newUrl, headers={'User-Agent': "Remindme tester by /u/Watchful1"}) objects = json.json()['data'] if len(objects) == 0: break for comment in objects: if comment['author'] == "RemindMeBot": continue previousEpoch = comment['created_utc'] - 1 time_string_old = find_reminder_time_old( comment['body'].lower(), static.TRIGGER_LOWER ) #find_reminder_time_old(comment['body'].lower(), False) time_string_new = utils.find_reminder_time(comment['body'].lower(), static.TRIGGER_LOWER) if time_string_old is not None: date_time_old = parse_time_old(time_string_old, current, None) date_time_new = utils.parse_time(time_string_new, current, None) if date_time_old != date_time_new: log.info( f"{utils.get_datetime_string(date_time_old, False, '%Y-%m-%d %H:%M:%S %Z').ljust(23) if date_time_old is not None else 'None'.ljust(23)} " f"| {utils.get_datetime_string(date_time_new, False, '%Y-%m-%d %H:%M:%S %Z').ljust(23) if date_time_new is not None else 'None'.ljust(23)} " f"| {time_string_old[:60].ljust(60) if time_string_old is not None else 'None'.ljust(60)} " f"| {time_string_new.ljust(60) if time_string_new is not None else 'None'.ljust(60)} " f"| https://www.reddit.com{comment['permalink']} ") count += 1 if count > 10000: breakOut = True break
cal = parsedatetime.Calendar() input_string = '''RemindMe! 24th of the month''' base_time_string = "2022-01-24 00:00:00 -0000" timezone_string = None #"America/Los_Angeles" if base_time_string: base_time = utils.datetime_as_timezone(utils.parse_datetime_string(base_time_string, False, '%Y-%m-%d %H:%M:%S %z'), "UTC") else: base_time = utils.datetime_now() format_string = '%Y-%m-%d %H:%M:%S %Z' log.info(f"Input string: {input_string}") time = utils.find_reminder_time(input_string, "remindme") if time is not None: log.info(f"Result: {time}") time_string = time else: log.info(f"No string found") sys.exit(0) log.info(f"Now: {base_time.strftime(format_string)}") try: date_time = dateparser.parse(time_string, languages=['en'], settings={"PREFER_DATES_FROM": 'future', "RELATIVE_BASE": base_time.replace(tzinfo=None)}) if date_time is not None: log.info(f"dateparser.parse: {date_time.strftime(format_string)}") except Exception: date_time = None