def getAvailableSlotsMsg(timestamps): websiteUrl = os.environ['WEBSITE_URL'] slotMessage = '' welcomeMessage = "Hello Dan! <br> " # Create the body of the message (a plain-text and an HTML version). if len(timestamps) == 0: welcomeMessage += "<h3>There are no empty slots in the next 36 hours</h3>" else: dbh = dbhandler.dbhandler() #delete all timestamps more than 2 days old dbh.deleteOldTimestamps(timestamps[0] + (2 * 24 * 60 * 60)) welcomeMessage += "<h3>The following slots are available within 36 hours:</h3><br>" for timestamp in timestamps: exists = dbh.exists(timestamp) if not exists: dbh.addToDb(timestamp) slot = util.getDateTime(timestamp) curMessage = "<p>" curMessage += "EXISTING" if exists else "NEW" curMessage += " SLOT: " curMessage += slot.strftime("%a %I:%M %p, %b %d") + " - " reservationLink = "<a href=" + websiteUrl + "/reserve?timestamp=" + str(timestamp) + ">" reservationLink += "Click here to reserve" + "</a>" slotMessage += curMessage + reservationLink + "</p>" print slotMessage html = welcomeMessage + slotMessage return html
def newAdminAPI(): if not ('token' in request.form): return local_make_response( json.dumps({ 'status': False, 'message': 'You are not logged in' })) db = dbhandler() if not (db.getUsername(request.form['token'])): return local_make_response( json.dumps({ 'status': False, 'message': 'Session not found' })) if ('username' in request.form) & ('password' in request.form): if db.registerAdmin(request.form['username'], request.form['password']): return local_make_response(json.dumps({'status': True})) else: return local_make_response( json.dumps({ 'status': False, 'message': 'Username is already taken' })) else: return local_make_response( json.dumps({ 'status': False, 'message': 'Form is not complete' }))
def sendDB(self): db = dbhandler.dbhandler(DATABASE) revenue = db.show_daily_revenue(TABLE) db.close() cred = (open('credentials.txt')).readline().split(" ") emailfrom = cred[0] emailto = str(self.email.text()) fileToSend = DATABASE username = cred[1] password = cred[2] subject = "Laporan, Today Revenue: Rp %s,00" %(str(revenue)) message = "Revenue: %s" %(str(revenue)) try: send_mail.send_mail(emailfrom,emailto,fileToSend,username,password,subject,message) msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Information) msg.setText('berhasil terkirim') msg.setWindowTitle('Success') msg.exec_() except : msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Information) msg.setText('gagal terkirim, cek koneksi') msg.setWindowTitle('Failed') msg.exec_()
def write_db(self): db = dbhandler.dbhandler(DATABASE) pesanan = [] for k in self.pesanan: pesanan.append(k+" "+str(self.pesanan[k][0])) db.insert_value(TABLE,pesanan,int(self.total.text())) self.pesanan = dict() self.jumlahHarga = [] db.close()
def __init__(self, db="project1_quiz_cs384.db"): self.logged_in = False self.database_name = db self.table_name = "project1_registration" self.index_tuples = index_tuples = [ ("NAME", "TEXT", "NOT NULL"), ("ROLL", "TEXT", "PRIMARY KEY", "NOT NULL"), ("PASSWORD", "CHAR(64)", "NOT NULL"), ("WHATSAPP", "VARCHAR(12)", "NOT NULL") ] self.table = dbhandler(self.database_name, self.table_name, self.index_tuples)
def callback(): db = dbhandler() signature = request.headers['X-Line-Signature'] body = request.get_data(as_text=True) try: events = parser.parse(body, signature) except InvalidSignatureError: abort(400) for event in events: if not isinstance(event, MessageEvent): continue if not isinstance(event.message, TextMessage): continue if (not (db.getPlayerName(event.source.user_id))): name = line_bot_api.get_profile(event.source.user_id).display_name db.addOut( event.source.iuser_id, 'Halo {}, selamat bergabung :3 :3 :3\n\nDaftar perintah:\n/baru : membuat permainan baru\n/mulai : memulai permainan\n/join <token> : memasuki permainan yang sudah dibuat orang lain\n/help : bantuan' .format(name)) db.addPlayer(event.source.user_id, name) db.addIn(event.source.user_id, event.message.text) splitted = event.message.text.split() if (splitted[0] == '/baru'): db.addAction(event.source.user_id, ACTION_CREATE_GAME) elif (splitted[0] == '/mulai'): db.addAction(event.source.user_id, ACTION_START_GAME) elif (splitted[0] == '/join'): if (len(splitted) > 1): db.addAction(event.source.user_id, ACTION_JOIN_GAME, splitted[1]) else: db.addOut( event.source.user_id, 'Tulis "/join <token>" untuk bergabung dengan game yang sudah ada atau "/baru" untuk memulai game yang baru.' ) elif (splitted[0] == '/help'): db.addOut( event.source.user_id, 'Daftar perintah:\n/baru : membuat permainan baru\n/mulai : memulai permainan\n/join <token> : memasuki permainan yang sudah dibuat orang lain\n/help : bantuan' ) else: db.addAction(event.source.user_id, ACTION_GUESS, ' '.join(splitted)) return make_response('OK')
def getPlayer(): db = dbhandler() if not (db.getUsername(request.args.get('token'))): return local_make_response( json.dumps({ 'status': False, 'message': 'Session not found' })) print(db.getUsername(request.args.get('toke'))) result = list(db.getPlayer()) for i in range(len(result)): result[i] = list(result[i]) return local_make_response(json.dumps({'status': True, 'data': result}))
def getInMessageAPI(playerId, lastId): db = dbhandler() if not (db.getUsername(request.args.get('token'))): return local_make_response( json.dumps({ 'status': False, 'message': 'Session not found' })) result = list(db.getInMessage(lastId=lastId, playerId=playerId)) for i in range(len(result)): result[i] = list(result[i]) result[i][0] = result[i][0].strftime('%m/%d/%Y (%H:%M:%S)') return local_make_response(json.dumps({'status': True, 'data': result}))
def getMyReservedSlotsMsg(timestamps): welcomeMessage = "<br>" slotMessage = "" if len(timestamps) == 0: welcomeMessage += "<h3>You don't have any reserved slots in the next 36 hours</h3>" else: dbh = dbhandler.dbhandler() welcomeMessage += "<h3>The following slots in the next 36 hours have been reserved by you:</h3><br>" for timestamp in timestamps: slot = util.getDateTime(timestamp) curMessage = "<p>" curMessage += " SLOT: " curMessage += slot.strftime("%a %I:%M %p, %b %d") slotMessage += curMessage + "</p>" print slotMessage html = welcomeMessage + slotMessage return html
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(457, 270) self.gridLayout_3 = QtWidgets.QGridLayout(Dialog) self.gridLayout_3.setObjectName("gridLayout_3") self.gridLayout_2 = QtWidgets.QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout_3.addLayout(self.gridLayout_2, 0, 0, 2, 2) self.tableWidget = QtWidgets.QTableWidget(Dialog) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(4) self.tableWidget.setRowCount(0) item = QtWidgets.QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(3, item) self.gridLayout_3.addWidget(self.tableWidget, 1, 1, 1, 1) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) db = dbhandler.dbhandler(DATABASE) size = db.get_size('pelanggan') datas = db.get_value('pelanggan') for data in datas: self.tableWidget.setRowCount(self.tableWidget.rowCount()+1) for i in range(len(data)): item = QtWidgets.QTableWidgetItem() if data[i]==None: item.setText("-") else: item.setText(str(data[i])) self.tableWidget.setItem(self.tableWidget.rowCount()-1,i,item)
def loginAPI(): if ('username' in request.form) & ('password' in request.form): db = dbhandler() token = db.loginAdmin(request.form['username'], request.form['password']) if token: return local_make_response( json.dumps({ 'status': True, 'token': token })) else: return local_make_response( json.dumps({ 'status': False, 'message': 'Username/password is wrong' })) else: return local_make_response( json.dumps({ 'status': False, 'message': 'Form is not complete' }))
def logoutAPI(): db = dbhandler() db.logoutAdmin(request.args.get('token')) return local_make_response(json.dumps({'status': True}))
import flask import datetime, json from dbhandler import dbhandler db = dbhandler() app = flask.Flask(__name__) app.secret_key = '@@$^%^$#$%@$#FsfdgsDFBDF12312' @app.route('/') def home(): if flask.session.get('logged_in') == True: return flask.redirect(flask.url_for('admin')) nav_links = {} nav_links['adminlogin'] = '******' nav_links['signup'] = 'Signup' nav_links['about'] = 'About' return flask.render_template("index.html", nav_links=nav_links, lable="Beer") @app.route('/getToken', methods=["GET", "POST"]) def gettoken(): if flask.session.get('token') == True: return flask.render_template("token.html", nav_links={"about": "About"}, tokenno=flask.session.get("token_no"), timeslot=flask.session.get("timeslot"), name=flask.session.get("name"), lable="Beer")
import dbhandler dbh = dbhandler.dbhandler() #dbh.addToDb(124) dbh.dropTable() #dbh.deleteOldTimestamps(1480730400) dbh.printAll()
def hapusDB(self): db = dbhandler.dbhandler(DATABASE) db.delete_all(TABLE)