diff --git a/app/delete_posts.py b/app/delete_posts.py index 8962c8d..c2467a3 100644 --- a/app/delete_posts.py +++ b/app/delete_posts.py @@ -13,26 +13,29 @@ def run(): delete = "DELETE FROM post WHERE created_utc < ? AND saved = ?" binds = [max_created_utc, False] cursor.execute(delete, binds) - print("Deleting posts from blocked subreddits") - select = "SELECT name FROM block WHERE name like '/r/%'" - binds = [row[0][3:] for row in cursor.execute(select).fetchall()] - bind_array = ",".join(["?"]*len(binds)) - binds.append(False) - delete = f"DELETE FROM post WHERE subreddit IN ({bind_array}) AND saved = ?" - cursor.execute(delete, binds) - print("Deleting posts from blocked users") - select = "SELECT name FROM block WHERE name like '/u/%'" - binds = [row[0][3:] for row in cursor.execute(select).fetchall()] - bind_array = ",".join(["?"]*len(binds)) - binds.append(False) - delete = f"DELETE FROM post WHERE author IN ({bind_array}) AND saved = ?" - cursor.execute(delete, binds) - print("Deleting posts with blocked words") - select = "SELECT name FROM block where name NOT LIKE '/u/%' AND name NOT LIKE '/r/%'" - binds = ["%"+row[0]+"%" for row in cursor.execute(select).fetchall()] - where_array = " OR ".join(["post LIKE ?"]*len(binds)) - delete = f"DELETE FROM post WHERE {where_array}" - cursor.execute(delete, binds) + # LIKE is case insensitive by default, meaning a block on the word "ICE" would catch words like "nice" + # causing posts to get deleted and then redownloaded over and over again. Commenting out for now, might fix later. + # See 'PRAGMA case_sensitive_like = ON' + #print("Deleting posts from blocked subreddits") + #select = "SELECT name FROM block WHERE name like '/r/%'" + #binds = [row[0][3:] for row in cursor.execute(select).fetchall()] + #bind_array = ",".join(["?"]*len(binds)) + #binds.append(False) + #delete = f"DELETE FROM post WHERE subreddit IN ({bind_array}) AND saved = ?" + #cursor.execute(delete, binds) + #print("Deleting posts from blocked users") + #select = "SELECT name FROM block WHERE name like '/u/%'" + #binds = [row[0][3:] for row in cursor.execute(select).fetchall()] + #bind_array = ",".join(["?"]*len(binds)) + #binds.append(False) + #delete = f"DELETE FROM post WHERE author IN ({bind_array}) AND saved = ?" + #cursor.execute(delete, binds) + #print("Deleting posts with blocked words") + #select = "SELECT name FROM block where name NOT LIKE '/u/%' AND name NOT LIKE '/r/%'" + #binds = ["%"+row[0]+"%" for row in cursor.execute(select).fetchall()] + #where_array = " OR ".join(["post LIKE ?"]*len(binds)) + #delete = f"DELETE FROM post WHERE {where_array}" + #cursor.execute(delete, binds) print("Deleting old media db rows") delete = "DELETE FROM media WHERE permalink NOT IN (SELECT permalink FROM post)" cursor.execute(delete)