976ae1a2 by Barry

Started database conversion

1 parent f28cb961
No preview for this file type
import json
import sqlite3
conn = sqlite3.connect('db.sqlite3')
def byteify(input):
if isinstance(input, dict):
return {byteify(key):byteify(value) for key,value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
def import_fortunes(conn):
fortune_file = 'fortunes.json'
json_data=open(fortune_file).read()
data = json.loads(json_data)
c = conn.cursor()
for fortune in data:
try:
c.execute("INSERT INTO fortunes (fortune, date_added) VALUES (?,'2016/01/18 00:00:00')", (fortune,))
except Exception as e:
print(e)
pass
conn.commit()
def import_jokes(conn):
joke_file = 'jokes.json'
json_data=open(joke_file).read()
data = json.loads(json_data)
c = conn.cursor()
for joke in data:
try:
c.execute("INSERT INTO jokes (joke, date_added) VALUES (?,'2016/01/18 00:00:00')", (joke,))
except Exception as e:
print(e)
pass
conn.commit()
def import_messages(conn):
deliveries_file = 'deliveries.json'
json_data=open(deliveries_file).read()
data = json.loads(json_data)
c = conn.cursor()
for username in data:
print("Username: %s" % username)
for author in data[username]:
try:
c.execute("INSERT INTO messages (message, delivery_time, channel, message_from, message_to, user_id) VALUES (?, ?, ?, ?, ?, ?)", (data[username][author]['message'], data[username][author]['delivery_time'],data[username][author]['channel'], author, username, data[username][author]['user_id']))
except Exception as e:
print(e)
pass
conn.commit()
import_jokes(conn)
import_fortunes(conn)
import_messages(conn)
\ No newline at end of file
......@@ -474,7 +474,7 @@ Stuff:
game_id = game['id']
if game_id == 0:
client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention()))
return
matched_usernames = []
for username in member_data:
if 'games_played' in member_data[username]:
......@@ -665,6 +665,9 @@ Stuff:
if message.content.startswith('!hello'):
client.send_message(message.channel, 'Hello {}!'.format(message.author.mention()))
if message.content.startswith('!deal'):
client.send_message(message.channel, 'You get {}!'.format(message.author.mention()))
@client.event
def on_ready():
print('Logged in as')
......