Advertisement
Guest User

funcs

a guest
Nov 26th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import mysql.connector
  2.  
  3.  
  4. #+--------------------------+
  5. #|Establish db connection |
  6. #+--------------------------+
  7.  
  8. def open_db(hostname, dbname, uname, pswd):
  9. return mysql.connector.connect(
  10. host=hostname, user=uname, passwd=pswd, db=dbname,buffered=True
  11. )
  12.  
  13.  
  14. #+--------------------------+
  15. #|Returns player's location |
  16. #+--------------------------+
  17. def location(db):
  18. cur = db.cursor()
  19. cur.execute("select roomID from hahmo where c_ID = 1");
  20. return (cur.fetchone())[0]
  21. #+---------------------------------------+
  22. #|Returns the given places' descrioption |
  23. #+---------------------------------------+
  24. def kuvaus(db, id):
  25. cur = db.cursor()
  26. cur.execute("select KUVAUS from room where roomID = " + str(id))
  27. return (cur.fetchone())[0]
  28.  
  29.  
  30. #+---------------------------------------+
  31. #|Returns the list of possible routes |
  32. #+---------------------------------------+
  33. def directions(db, id):
  34. cur = db.cursor()
  35. cur.execute("select E, W, S, N, D, U from room where roomID = " + str(id))
  36. rivi = cur.fetchone()
  37. kompassi = ['E', 'W', 'S', 'N', 'D', 'U']
  38. directions = []
  39. for i in range(0, 4):
  40. if rivi[i] is not None:
  41. directions.append(kompassi[i])
  42. return directions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement