Last active
April 21, 2023 13:33
-
-
Save tildejustin/11088a8620adb6f77ccf5c5e09d8c266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2023 tildejustin | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
import os | |
import sys | |
import tkinter as tk | |
from itertools import takewhile, repeat | |
from tkinter import filedialog | |
# only change this if you know what you're doing | |
filter_list: str = "12eye_list_1.16.txt" | |
def main() -> None: | |
# make window scaling look decent on my laptop | |
try: | |
# noinspection PyUnresolvedReferences | |
from ctypes import windll | |
except ImportError: | |
pass | |
else: | |
windll.shcore.SetProcessDpiAwareness(1) | |
# a little tk magic | |
root = tk.Tk() | |
root.withdraw() | |
filepath = filedialog.askopenfilename(initialdir=os.curdir) | |
root.destroy() | |
if not filepath: | |
print("no file, exiting") | |
sys.exit() | |
line_num = line_count(filter_list) | |
print("lines in seed list:", line_num) | |
with open(filepath) as sister_file: | |
sisters = {sister_seed.strip() for sister_seed in sister_file.readlines()} | |
counter = 0 | |
check_num = line_num // 10 + 1 | |
sister_twelve_eyes = [] | |
with open(filter_list) as file: | |
while seed := file.readline().split(" ")[0]: | |
if seed in sisters: | |
sister_twelve_eyes.append(seed) | |
counter += 1 | |
if counter % check_num == 0: | |
print(f"progress: {counter * 100 // line_num}%") | |
with open(filepath.split(".")[0] + "_filtered_twelve_eyes.txt", "w") as outfile: | |
outfile.write("\n".join(sister_twelve_eyes)) | |
# https://stackoverflow.com/a/27517681 | |
def line_count(filename): | |
with open(filename, "rb") as f: | |
buf_gen = takewhile(lambda x: x, (f.raw.read(1024 * 1024) for _ in repeat(None))) | |
return sum(buf.count(b"\n") for buf in buf_gen if buf) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment