# connect to database # try: connection = pymysql.connect(host=dbhost, user=dbuser, password=dbpassword, db=db, port=int(dbport), charset='utf8mb4', autocommit='True') cursor = connection.cursor() except: log("can not connect to database","webhook") quit() if db_need_update(cursor): log("Your DB-Version is to low. Please start dbupdate.py first","webhook") quit() # get bot information # bot = telepot.Bot(token) try: botident = bot.getMe() botname = botident['username'] botcallname = botident['first_name'] botid = botident['id'] try: cursor.execute("insert into bot values ('%s','%s')" % (botid,botname)) except: pass
try: connection = pymysql.connect(host=dbhost, user=dbuser, password=dbpassword, db=db, port=int(dbport), charset='utf8mb4', autocommit='True') cursor = connection.cursor() except: print("can not connect to database") raise ################## # check DB-Version if db_need_update(connection.cursor()): print("Your DB-Version is to low. Please start dbupdate.py first") quit() if (args.a or args.d or args.bl) and args.chatid == None: print("This Argument requires a ChatID") quit() if args.a: try: cursor.execute("insert into userallow value('%s')" % args.chatid) except: pass print("Allow ChatId {}".format(args.chatid)) elif args.d: cursor.execute("delete from userallow where chatid = '%s'" % args.chatid)