Started database conversion
Showing
4 changed files
with
74 additions
and
1 deletions
db.sqlite3
0 → 100644
No preview for this file type
db_import.py
0 → 100644
1 | import json | ||
2 | import sqlite3 | ||
3 | |||
4 | conn = sqlite3.connect('db.sqlite3') | ||
5 | |||
6 | def byteify(input): | ||
7 | if isinstance(input, dict): | ||
8 | return {byteify(key):byteify(value) for key,value in input.iteritems()} | ||
9 | elif isinstance(input, list): | ||
10 | return [byteify(element) for element in input] | ||
11 | elif isinstance(input, unicode): | ||
12 | return input.encode('utf-8') | ||
13 | else: | ||
14 | return input | ||
15 | |||
16 | def import_fortunes(conn): | ||
17 | fortune_file = 'fortunes.json' | ||
18 | |||
19 | |||
20 | json_data=open(fortune_file).read() | ||
21 | data = json.loads(json_data) | ||
22 | |||
23 | c = conn.cursor() | ||
24 | |||
25 | for fortune in data: | ||
26 | try: | ||
27 | c.execute("INSERT INTO fortunes (fortune, date_added) VALUES (?,'2016/01/18 00:00:00')", (fortune,)) | ||
28 | except Exception as e: | ||
29 | print(e) | ||
30 | pass | ||
31 | conn.commit() | ||
32 | |||
33 | def import_jokes(conn): | ||
34 | joke_file = 'jokes.json' | ||
35 | |||
36 | |||
37 | json_data=open(joke_file).read() | ||
38 | data = json.loads(json_data) | ||
39 | |||
40 | c = conn.cursor() | ||
41 | |||
42 | for joke in data: | ||
43 | try: | ||
44 | c.execute("INSERT INTO jokes (joke, date_added) VALUES (?,'2016/01/18 00:00:00')", (joke,)) | ||
45 | except Exception as e: | ||
46 | print(e) | ||
47 | pass | ||
48 | conn.commit() | ||
49 | |||
50 | def import_messages(conn): | ||
51 | deliveries_file = 'deliveries.json' | ||
52 | |||
53 | json_data=open(deliveries_file).read() | ||
54 | data = json.loads(json_data) | ||
55 | |||
56 | c = conn.cursor() | ||
57 | |||
58 | for username in data: | ||
59 | print("Username: %s" % username) | ||
60 | for author in data[username]: | ||
61 | try: | ||
62 | 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'])) | ||
63 | except Exception as e: | ||
64 | print(e) | ||
65 | pass | ||
66 | conn.commit() | ||
67 | |||
68 | import_jokes(conn) | ||
69 | import_fortunes(conn) | ||
70 | import_messages(conn) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -474,7 +474,7 @@ Stuff: | ... | @@ -474,7 +474,7 @@ Stuff: |
474 | game_id = game['id'] | 474 | game_id = game['id'] |
475 | if game_id == 0: | 475 | if game_id == 0: |
476 | client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention())) | 476 | client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention())) |
477 | 477 | return | |
478 | matched_usernames = [] | 478 | matched_usernames = [] |
479 | for username in member_data: | 479 | for username in member_data: |
480 | if 'games_played' in member_data[username]: | 480 | if 'games_played' in member_data[username]: |
... | @@ -665,6 +665,9 @@ Stuff: | ... | @@ -665,6 +665,9 @@ Stuff: |
665 | if message.content.startswith('!hello'): | 665 | if message.content.startswith('!hello'): |
666 | client.send_message(message.channel, 'Hello {}!'.format(message.author.mention())) | 666 | client.send_message(message.channel, 'Hello {}!'.format(message.author.mention())) |
667 | 667 | ||
668 | if message.content.startswith('!deal'): | ||
669 | client.send_message(message.channel, 'You get {}!'.format(message.author.mention())) | ||
670 | |||
668 | @client.event | 671 | @client.event |
669 | def on_ready(): | 672 | def on_ready(): |
670 | print('Logged in as') | 673 | print('Logged in as') | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment