Simplified the inputs to INSERT commands, also packs list as JSON object so it can be unpacked at other side

This commit is contained in:
2017-03-05 14:59:20 +01:00
parent 4270c80e12
commit ceb03ba7a7

View File

@@ -3,9 +3,9 @@
# @Author: KevinMidboe # @Author: KevinMidboe
# @Date: 2017-03-04 16:50:09 # @Date: 2017-03-04 16:50:09
# @Last Modified by: KevinMidboe # @Last Modified by: KevinMidboe
# @Last Modified time: 2017-03-05 13:09:10 # @Last Modified time: 2017-03-05 14:48:17
import os, sqlite3, re import os, sqlite3, re, json
from fuzzywuzzy import process from fuzzywuzzy import process
from langdetect import detect from langdetect import detect
from pprint import pprint from pprint import pprint
@@ -116,20 +116,22 @@ def addToDB(episodeInfo):
conn = sqlite3.connect(dbPath) conn = sqlite3.connect(dbPath)
c = conn.cursor() c = conn.cursor()
original = '"' + episodeInfo['original'] + '",' original = episodeInfo['original']
full_path = '"' + episodeInfo['full_path'] + '",' full_path = episodeInfo['full_path']
name = '"' + episodeInfo['name'] + '",' name = episodeInfo['name']
season = '"' + episodeInfo['season'] + '",' season = episodeInfo['season']
episode = '"' + episodeInfo['episode'] + '",' episode = episodeInfo['episode']
media_items = '"' + str(episodeInfo['media_items']) + '",' media_items = json.dumps(episodeInfo['media_items'])
subtitles = '"' + str(episodeInfo['subtitles']) + '",' subtitles = json.dumps(episodeInfo['subtitles'])
trash = '"' + str(episodeInfo['trash']) + '",' trash = json.dumps(episodeInfo['trash'])
tweet_id = episodeInfo['tweet_id'] + ',' tweet_id = episodeInfo['tweet_id'] + ','
verified = '"' + episodeInfo['verified'] + '"' verified = episodeInfo['verified']
print((media_items))
try: try:
c.execute('INSERT INTO stray_episodes VALUES ('+ original + full_path + name + season\ c.execute('INSERT INTO stray_episodes VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [original,\
+ episode + media_items + subtitles + trash + 'NULL,' + verified + ')') full_path, name, season, episode, media_items, subtitles, trash, None, verified])
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
print('Episode already registered') print('Episode already registered')