Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. def disconnectmysql(cursor,cnx):
  2. emp_no = cursor.lastrowid
  3. cnx.commit()
  4. cursor.close()
  5. cnx.close()
  6.  
  7. def connectmysql():
  8. cnx = connection.MySQLConnection(user=usermariadb,
  9. password=passwordmariadb,
  10. host=hostmariadb,
  11. database=databasemariadb)
  12. cursor=cnx.cursor()
  13. return cursor, cnx
  14.  
  15. @bot.command('richiesta')
  16. def richiesta_command(chat,message,args):
  17. sender=message.sender
  18. cursor, cnx = connectmysql()
  19. if str(message.text)=="/richiesta":
  20. text_message="invia la richiesta in questo modo <strong> /richiesta richiesta </strong> "
  21. else:
  22. querry="SELECT data_richiesta FROM info_richieste WHERE id_utente_richiedente='"+str(sender.id)+"'order by id_richiesta desc LIMIT 1"
  23. datatest=' '
  24. cursor.execute(querry)
  25. for row in cursor.fetchall():
  26. datatest=row[0]
  27.  
  28. chat.send(str(datatest))
  29.  
  30. richiesta=str(message.text[10:])
  31. querry="INSERT INTO info_richieste (contenuto_richiesta, id_utente_richiedente, status,data_richiesta) VALUES ('"+str(richiesta)+"','"+str(sender.id)+"', 0,'"+str(dt.datetime.now())+"')"
  32. cursor.execute(querry)
  33. giorni_attesa=14
  34. text_message="richiesta: "+richiesta+" effettuata ricordati che non puoi effetuare una nuova richiesta per 2 settimane tranne se lo diciamo noi admin quindi la tua prossima richiesta la potrai fare il "+str(date.fromordinal(date(date.today().year, 1, 1).toordinal() + dt.datetime.today().day +giorni_attesa))
  35. chat.send(text_message,syntax="HTML")
  36. text_message="#richiesta \nutente:"+str(sender.name)+"\ncon username:@"+str(sender.username)+"\ned id:"+str(sender.id)+"\na fatto la richiesta:\n"+richiesta+"\nne potrà fare un altra il:"+str(date.fromordinal(date(date.today().year, 1, 1).toordinal() + dt.datetime.today().day +giorni_attesa))+"\ntag:#richiesta"+str(sender.id)
  37.  
  38. querry="SELECT idchattg FROM chatsend WHERE tipo=0"
  39. cursor.execute(querry)
  40. for row in cursor.fetchall():
  41. bot.chat(row[0]).send(text_message,syntax="HTML")
  42. disconnectmysql(cursor,cnx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement