def process(self): def job(eid, text, lineid, location=None, stickerid=180): self.reminder.push(text, stickerid, lineid, location) eventManager = Event() start = datetime.today() + timedelta(days=-1) end = datetime.today() + timedelta(days=2) events = eventManager.search({"datetime": {"$gte": start, "$lt": end}}) for event in events: if event["datetime"] > (datetime.now() + timedelta(hours=7)): location = None if event.get("loc"): location = event["loc"] date = str( datetime.strptime(str(event["datetime"]), "%Y-%m-%d %H:%M:%S").strftime( "tanggal %d/%m jam %H:%M WIB")) dta = event["datetime"] + timedelta(hours=-8) namajadwal1 = event["about"].replace("_", " ") reminding = "jangan lupa " + date + " ada jadwal " + namajadwal1 eid = event["about"] + event["lineid"] self.reminder.add(eid, dta, job, ( reminding, event["lineid"], location, )) print(self.reminder.scheduler.queue)
def act(self, namajadwal, reminder, state): try: ev1 = Event() ev1.removeQuery({"lineid": state['id'], "about": namajadwal}) reminder.remove(namajadwal + str(state['id'])) namajadwal = namajadwal.replace("_", " ") return (state, "acara " + namajadwal + " telah dihapus") except: namajadwal = namajadwal.replace("_", " ") return (state, "Maaf kak, jadwal " + namajadwal + " tidak ada :( ")
def act(self, event_name, pengeluaran_name, people_name, state, duit=-1): if Event().searchOne({"lineid": state['id'], "about": event_name}): duit = float(duit) if duit < 0: state = { **state, 'pengeluaran_name': pengeluaran_name, 'event_name': event_name, 'people_name': people_name, 'before_state': state['state_id'] } return ( state, "Masukkan jumlah duit \nBisa lewat teks atau input bon") try: ev1 = Expense(state['id'], pengeluaran_name, event_name, people_name, duit) ev1.create() event_name = event_name.replace("_", " ") pengeluaran_name = pengeluaran_name.replace("_", " ") return (state, "Pengeluaran " + pengeluaran_name + " telah ditambahkan di acara " + event_name) except: print(sys.exc_info()) return (state, errorCreateUpdatePengeluaran) else: event_name = event_name.replace("_", " ") return (state, "acara " + event_name + " belum ada :( ")
def act(self, state): try: ev1 = Event() events = ev1.search({"lineid": state['id']}) if events.count() == 0: output = "Maaf tidak ada jadwal di database bawel :(" return (state, output) licc = [] ite = 0 lievent = [] for event in events: ite += 1 about = event['about'].replace("_", " ")[0:20] date = str( datetime.strptime( str(event['datetime']), "%Y-%m-%d %H:%M:%S").strftime("%d-%m %H:%M")) text = "Acara tentang " + about + " diadakan pada " + str(date) cc = CarouselColumn( text=text, title=about, actions=[ PostbackTemplateAction(label='Lihat pengeluaran', data='/lihatpengeluaran ' + event['about']), PostbackTemplateAction(label='Lihat daftar ikut', data='/reportjadwal ' + event['about']), # PostbackTemplateAction(label='Hapus jadwal', data='/hapusjadwal '+event['about']), ]) licc.append(cc) if ite == 4: carousel_template = CarouselTemplate(columns=licc) template_message = TemplateSendMessage( alt_text='List jadwal', template=carousel_template) ite = 0 lievent.append(template_message) licc = [] if ite > 0: carousel_template = CarouselTemplate(columns=licc) template_message = TemplateSendMessage( alt_text='List jadwal', template=carousel_template) lievent.append(template_message) return (state, lievent) except: print(sys.exc_info())
def act(self, namajadwal, hari, bulan, tahun, jam, menit, reminder, state): try: dtime = check_date_input(hari, bulan, tahun, jam, menit) ev1 = Event(state['id'], namajadwal, hari, bulan, tahun, jam, menit, 0) ev1.update() print('nande') except: print(sys.exc_info()) return ( state, "Maaf kak, bawel ga ngerti, coba nambahjadwalnya kaya gini ya kak'si bawel tolong ubah acara/event/jadwal nonton bareng tanggal 29 Maret jam 5.50 sore'" ) try: reminder.modify(namajadwal + str(state['id']), dtime) namajadwal = namajadwal.replace("_", " ") return (state, "acara " + namajadwal + " telah diubah") except: print(sys.exc_info()) namajadwal = namajadwal.replace("_", " ") return (state, "acara " + namajadwal + " telah diubah")
def act(self, namajadwal, hari, bulan, tahun, jam, menit, reminder, state, location=None): def job(eid, text, lineid, location=None, stickerid=180): reminder.push(text, stickerid, lineid, location) try: dt = check_date_input(hari, bulan, tahun, jam, menit) ev1 = Event(state['id'], namajadwal, hari, bulan, tahun, jam, menit, location, 0) ev1.create() dta = dt + timedelta(hours=8) date = str( datetime.strptime(str(dta), "%Y-%m-%d %H:%M:%S").strftime( "tanggal %d/%m jam %H:%M WIB")) namajadwal1 = namajadwal.replace("_", " ") reminding = "jangan lupa " + date + " ada jadwal " + namajadwal1 reminder.add(namajadwal + str(state['id']), dt, job, ( reminding, state['id'], location, )) return (state, "acara " + namajadwal1 + " telah ditambah") except: print(sys.exc_info()) return ( state, "Maaf kak, bawel ga ngerti, coba nambahjadwalnya kaya gini ya kak'si bawel tolong tambah acara/event/jadwal nonton bareng tanggal 29 Maret jam 5.50 sore'" )
def act(self, event_name, pengeluaran_name, people_name, duit, state): if Event().searchOne({"lineid": state['id'], "about": event_name}): try: ex1 = Expense(state['id'], pengeluaran_name, event_name, people_name, duit) ex1.update() pengeluaran_name = pengeluaran_name.replace("_", " ") return (state, "Pengeluaran " + pengeluaran_name + " berhasil dirubah") except: print(sys.exc_info()) return (state, errorCreateUpdatePengeluaran) else: event_name = event_name.replace("_", " ") return (state, "acara " + event_name + " belum ada :( ")
def act(self, event_name, people_name, state): try: if Event().searchOne({"lineid": state['id'], "about": event_name}): ex1 = Expense(state['id'], 'ikut', event_name, people_name, 0) ex1.create() event_name = event_name.replace("_", " ") return (state, people_name + " berhasil ikut pada " + event_name) else: event_name = event_name.replace("_", " ") return (state, "acara " + event_name + " belum ada :( ") except: print(sys.exc_info()) return ( state, "Maaf kak, bawel ga ngerti, coba nambahjadwalnya kaya gini ya kak'si bawel ikut acara/event/jadwal nonton bareng oleh kevin'" )