Advertisement
Guest User

Untitled

a guest
Jul 14th, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. # returns if an item is in a user's notify list
  2. def pref_exists(userID, item):
  3.     conn = psycopg2.connect("dbname={0} user={1} password={2} host={3}".format(config.mysql['db'], config.mysql['user'], config.mysql['passwd'], config.mysql['host']))
  4.     cursor = conn.cursor()
  5.     cursor.execute("SELECT count(item) from user_prefs where discordID = %s and item = %s", (str(userID), str(item)))
  6.     data = cursor.fetchall()
  7.     cursor.close()
  8.     conn.close()
  9.     return (data[0])[0] > 0
  10.  
  11.  
  12. # returns the list of preferences for a user
  13. def user_prefs(userID):
  14.     conn = psycopg2.connect("dbname={0} user={1} password={2} host={3}".format(config.mysql['db'], config.mysql['user'], config.mysql['passwd'], config.mysql['host']))
  15.     cursor = conn.cursor()
  16.     cursor.execute("SELECT item FROM user_prefs WHERE discordID = %s", (str(userID),))
  17.     data = cursor.fetchall()
  18.     cursor.close()
  19.     conn.close()
  20.     return data
  21.  
  22. # returns the list of users for an item
  23. def users(item):
  24.     conn = psycopg2.connect("dbname={0} user={1} password={2} host={3}".format(config.mysql['db'], config.mysql['user'],
  25.                                                                                config.mysql['passwd'],
  26.                                                                                config.mysql['host']))
  27.     cursor = conn.cursor()
  28.     cursor.execute("SELECT DISTINCT discordID from user_prefs WHERE item = %s", (str(item),))
  29.     data = cursor.fetchall()
  30.     cursor.close()
  31.     conn.close()
  32.     return data
  33.  
  34. # gets the server that a user is in
  35. def user_server(discordID):
  36.     conn = psycopg2.connect("dbname={0} user={1} password={2} host={3}".format(config.mysql['db'], config.mysql['user'],
  37.                                                                                config.mysql['passwd'],
  38.                                                                                config.mysql['host']))
  39.     cursor = conn.cursor()
  40.     cursor.execute("SELECT DISTINCT server from user_prefs WHERE discordID = %s", (str(discordID),))
  41.     data = cursor.fetchall()
  42.     cursor.close()
  43.     conn.close()
  44.     print(data[0])
  45.     return (data[0])[0].strip()
  46.  
  47. def user_exists(discordID):
  48.     conn = psycopg2.connect("dbname={0} user={1} password={2} host={3}".format(config.mysql['db'], config.mysql['user'],
  49.                                                                                config.mysql['passwd'],
  50.                                                                                config.mysql['host']))
  51.     cursor = conn.cursor()
  52.     cursor.execute("SELECT count(discordID) from user_prefs WHERE discordID = %s", (str(discordID),))
  53.     data = cursor.fetchall()
  54.     cursor.close()
  55.     conn.close()
  56.     return (data[0])[0] > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement