Last active
January 23, 2017 12:57
-
-
Save MorkHub/85623a204c80b3cff50cf5d423039ab7 to your computer and use it in GitHub Desktop.
SQL for python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.log* | |
secret.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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