I'm struggling to find an answer to how I can execute a Python variable:%s or ({url}) inside a LIKE %var% startment.
The percent signs cause me problems...syntax error
Here's a sample dump of the SQLite database I'm trying query from:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "user_cats" (
`category` TEXT,
`uploader` TEXT,
`folder` TEXT,
`playlists` TEXT,
`playlist_image` TEXT,
`save_directory` TEXT
);
INSERT INTO user_cats VALUES('Comics','ComicsExplained','DC Rebirth','[''New to DC Comics? Start here!'']',NULL,'%USERPROFILE%\Videos\Online Videos\Comics\ComicsExplained\');
INSERT INTO user_cats VALUES('Comics','Comicstorian',NULL,NULL,NULL,NULL);
INSERT INTO user_cats VALUES('Video Games','IGN','Daily Fix','[''Daily Fix'']',NULL,'%USERPROFILE%\Videos\Online Videos\Video Games\IGN\Daily Fix\');
INSERT INTO user_cats VALUES('Comics','Marvel Entertainment','Marvel Top 10','[''Marvel Top 10'']',NULL,'%USERPROFILE%\Videos\Online Videos\Comics\Marvel Entertainment\');
INSERT INTO user_cats VALUES('','ScrewAttack!',NULL,NULL,NULL,NULL);
COMMIT;
What I'd like to do is have a formula (that I'll likely turn into an object method) that uses youtube-dl to retrieve the uploader and playlist title.
Then use the database to route files to different save locations, and - probably save other information. But, I'm having problems with the SELECT statement and percentage signs. The error depends how I edit the statement - various syntax or unexpected character etc. (It would probably not help to type every error I've gotten - it's a problem with the variable assignment - not the statement.
If I query SQLite (outside of Python) using simply...
SELECT save_directory FROM user_cats WHERE uploader='IGN' AND playlists LIKE '%ail%';
Bingo. Works.
def save_dir (uploader, playlist):
query = "SELECT save_directory FROM user_cats WHERE uploader=({ul}) AND playlists LIKE '%%({pl})%%'.format(ul = uploader, pl = playlist)".format(ul=uploader, pl=playlist))
c.execute(query)
all_rows = c.fetchall()
print('1):', all_rows)