Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from tkinter import *
- import os
- import sqlite3
- def text_to_array(text):
- ret = []
- with_spaces = text.split(',')
- for i in with_spaces:
- j = i.strip(' ')
- j = j.strip('\n')
- ret.append(j)
- return ret
- def create_tables():
- c = conn.cursor()
- sql = '''
- CREATE TABLE IF NOT EXISTS profiles
- (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- name TEXT
- )
- '''
- c.execute(sql)
- conn.commit()
- def insert_profile(name):
- c = conn.cursor()
- sql = '''
- INSERT OR IGNORE INTO profiles(name) VALUES(?);
- '''
- c.execute(sql, (name,))
- conn.commit()
- def insert_profiles(profiles):
- c = conn.cursor()
- sql = '''
- INSERT OR IGNORE INTO profiles(name) Values(?);
- '''
- c.executemany(sql, profiles)
- conn.commit()
- def get_profiles():
- profiles = []
- c = conn.cursor()
- for row in c.execute("SELECT name FROM profiles"):
- profiles.append(row[0])
- print(len(profiles))
- return profiles
- def import_profiles():
- blacklist = get_list('blacklist.txt')
- blacklist_tuples = []
- for name in blacklist:
- blacklist_tuples.append((name,),)
- insert_profiles(blacklist_tuples)
- def db_get_filtered():
- current_text = my_gui.input.get("1.0", END)
- current = text_to_array(current_text)
- blacklist = get_profiles()
- ret = []
- for name in current:
- if name not in blacklist:
- ret.append(name)
- return ret
- def export_profiles():
- profiles = get_profiles()
- for name in profiles:
- os.system('echo "' + name + "," + '" >> export.csv')
- class MyFirstGUI:
- def __init__(self, master):
- self.master = master
- self.buttons = []
- master.title("Blacklist filterers")
- #create_tables()
- #get_profiles()
- #import_profiles()
- #export_profiles()
- self.init_controls()
- def init_controls(self):
- text = Text(self.master, height=1, width=5)
- text.pack(side=LEFT)
- self.input = text
- button = Button(self.master, text="go", command = lambda: self.populate())
- button.pack(side=LEFT)
- self.go_button = button
- def populate(self):
- for button in self.buttons:
- button.destroy()
- candidates = db_get_filtered()
- self.input.delete("1.0", END)
- for c in candidates:
- self.add_button(c)
- def add_button(self, name):
- button = Button(self.master, text=name, command = lambda: self.blacklist(name, button))
- button.pack()
- self.buttons.append(button)
- def blacklist(self, name, button):
- payload = name + ", "
- #os.system('echo "' + payload + '" >> blacklist.txt')
- insert_profile(name)
- button.destroy()
- root = Tk()
- conn = sqlite3.connect("blacklist.db");
- create_tables()
- my_gui = MyFirstGUI(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement