Skip to content

Instantly share code, notes, and snippets.

@MorkHub
Last active January 23, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MorkHub/85623a204c80b3cff50cf5d423039ab7 to your computer and use it in GitHub Desktop.
Save MorkHub/85623a204c80b3cff50cf5d423039ab7 to your computer and use it in GitHub Desktop.
SQL for python
*.log*
secret.py
...
import MySQLdb
from secret import credentials
cnx = MySQLdb.connect(user=credentials['user'], db=credentials['database'], passwd=credentials['password'])
cursor = cnx.cursor()
query = ("SELECT * FROM `q2` WHERE `id`='{}' ORDER BY RAND() LIMIT 1".format(id))
cursor.execute(query)
if cursor.rowcount < 1:
query = ("SELECT * FROM `q2` ORDER BY RAND() LIMIT 1")
cursor.execute(query)
for (id,quote,author,date,_,_) in cursor:
print("ID: {}\nFROM: {}\nDATE: {}\nQUOTE: {}".format(id,author,date,quote))
cursor.close()
cnx.close()
...
client.run(credentials['oauth_token'],bot=true)
credentials = {
'sql' = 'themork.co.uk'
'user' = 'readonly',
'password' = '',
'database' = 'my_themork',
'oauth_token' = '',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment