def do_POST(self): parsed_path = urlparse(self.path) if parsed_path.path != "/addDoc" and parsed_path.path != "/deleteDoc": self.write_response("failed") return ctype, pdict = parse_header(self.headers['content-type']) if ctype == 'multipart/form-data': post_vars = parse_multipart(self.rfile, pdict) elif ctype == 'application/x-www-form-urlencoded' or ctype == "application/json": length = int(self.headers['content-length']) post_vars = json.loads(self.rfile.read(length)) else: self.write_response("failed") return if parsed_path.path == "/addDoc": Documents().insert(post_vars) elif parsed_path.path == "/deleteDoc": Documents().delete(post_vars["id"]) self.write_response("ok")
def do_GET(self): parsed_path = urlparse(self.path) if parsed_path.path == "/all": self.write_json(Documents().select_all()) return if parsed_path.path == "/" or str(parsed_path.path).endswith("html")\ or str(parsed_path.path).endswith(".js"): self.default() if parsed_path.path == "/sun.jpg": img_name = self.path img_file = open(img_name[1:], 'rb').read() self.send_response(200) self.send_header('Content-type', 'image/jpg') self.end_headers() self.wfile.write(img_file)
def slack_list(self, data, conversation_id, user): input_text = data.split() response = "\n" if input_text is None or len(input_text) == 2: self.user = "******" else: self.user = input_text[2] if self.user == "users": records = self.doc.select_users() if records is None or len(records) == 0: response = "`No reminders - every thing is clean` :beach_with_umbrella:" else: records = [str(rec) for rec in records] response += "```Please give doc list <username> With username as one of the below.\n\n" + "\n".join(records) + "```\n\n" else: recs = self.doc.select_user_records(self.user) if recs is None or len(recs) == 0: response = "`No reminders - every thing is clean` :beach_with_umbrella:" else: r, e = Documents().get_records_to_notify(datetime.combine(datetime.today(), datetime.min.time())) expire_ids = list() for ex_rec in e: print(ex_rec) expire_ids.append(ex_rec["Id"]) for r in recs: mark_red = False if r["Id"] in expire_ids: mark_red = True response += "*Id*: `%s`\n" % str(r["Id"]) else: response += "*Id*: %s\n" % str(r["Id"]) for k in r: if k == "Id": continue if mark_red: response += "*%s*: `%s`\n" % (k, str(r[k])) else: response += "*%s*: %s\n" % (k, str(r[k])) if r["Id"] in expire_ids: response += "`" response += "\n" return response
class Notify: LAST_NOTIFY_DATE = dict() @staticmethod def enable_disable_features(): EMailNotification.update_feature() SlackNotification.update_feature() WhatsAppNotification.update_feature() SMSNotification.update_feature() @staticmethod def setup(): Notify.enable_disable_features() EMailNotification.email_setup() def __init__(self): self.doc = Documents() Notify.enable_disable_features() def check_notification(self): check_date = datetime.combine(datetime.today(), datetime.min.time()) logging.info("check_date: %s" % check_date) to_notify, already_expired = self.doc.get_records_to_notify(check_date) if len(to_notify) <= 0: return notification_channel = [ SlackNotification.notify, EMailNotification.send_email, WhatsAppNotification.notify_through_whats_app, SMSNotification.notify_through_sms ] for nc in notification_channel: if Notify.LAST_NOTIFY_DATE.get(nc.__name__) is None or \ check_date != Notify.LAST_NOTIFY_DATE.get(nc.__name__): logging.info("calling " + str(nc.__name__)) if nc(to_notify, str(check_date).split()[0]) is True: Notify.LAST_NOTIFY_DATE[nc.__name__] = check_date else: logging.info( str(nc.__name__) + " previously notified on " + str(Notify.LAST_NOTIFY_DATE.get(nc.__name__)))
class Reminder: def __init__(self): self.user = None self.doc = Documents() def remove_reminder(self, data, conversation_id, user): input_text = data.split() try: if input_text is None or len(input_text) != 3: response = "`please provide the id of reminder to delete it`" else: if not self.doc.is_document_present(input_text[2]): response = "`please provide a valid id of reminder to delete it`" else: self.doc.delete_document(int(input_text[2])) response = "`deleted successfully`" except Exception as e: print(e) traceback.print_exc() response = "`please provide a valid id of reminder to delete it`" return response def add_new_reminder(self, data, conversation_id, user): if Conversation.is_active_conversation(conversation_id): next_question = Conversation.get_open_question_response(conversation_id, str(data)) if next_question is None: self.doc.insert(Conversation.active_con.get(conversation_id)) del Conversation.active_con[conversation_id] response = ":floppy_disk: _Document inserted_" else: extra = "" if next_question == "DateOfExpire": extra = " (format MM/DD/YYYY - Eg 05/31/2020 will be may 5th of 2020)" response = "Please give input for %s%s: " % (next_question, extra) else: Conversation.active_con[conversation_id] = {"command": data} for column in self.doc.INSERT_COLUMNS: Conversation.active_con[conversation_id][column] = None next_question = Conversation.get_open_question_response(conversation_id, None) extra = "" if str(next_question).lower().find("date") >= 0: extra = " (format MM/DD/YYYY - Eg 05/31/2020 will be may 5th of 2020)" elif str(next_question).lower() in ["RemindStart", "RemindFrequency"]: extra = " (format 1M for 1 month, 3M for 3 Months, 1W for one week, 1Y for one year - " \ "only M/W/Y is supported)" response = "Please give input for %s%s: " % (next_question, extra) return response def slack_list(self, data, conversation_id, user): input_text = data.split() response = "\n" if input_text is None or len(input_text) == 2: self.user = "******" else: self.user = input_text[2] if self.user == "users": records = self.doc.select_users() if records is None or len(records) == 0: response = "`No reminders - every thing is clean` :beach_with_umbrella:" else: records = [str(rec) for rec in records] response += "```Please give doc list <username> With username as one of the below.\n\n" + "\n".join(records) + "```\n\n" else: recs = self.doc.select_user_records(self.user) if recs is None or len(recs) == 0: response = "`No reminders - every thing is clean` :beach_with_umbrella:" else: r, e = Documents().get_records_to_notify(datetime.combine(datetime.today(), datetime.min.time())) expire_ids = list() for ex_rec in e: print(ex_rec) expire_ids.append(ex_rec["Id"]) for r in recs: mark_red = False if r["Id"] in expire_ids: mark_red = True response += "*Id*: `%s`\n" % str(r["Id"]) else: response += "*Id*: %s\n" % str(r["Id"]) for k in r: if k == "Id": continue if mark_red: response += "*%s*: `%s`\n" % (k, str(r[k])) else: response += "*%s*: %s\n" % (k, str(r[k])) if r["Id"] in expire_ids: response += "`" response += "\n" return response
def __init__(self): self.user = None self.doc = Documents()
def __init__(self): self.doc = Documents() Notify.enable_disable_features()