Last active
October 26, 2022 15:42
-
-
Save guyskk/84d41f275d1510a1c127f64d55307e2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
SQL = "INSERT INTO table (`value1`,`value2`,) VALUES ('%s','%s');\n" | |
def main(): | |
for fname in os.listdir("."): | |
# step1 | |
name, ext = os.path.splitext(fname) | |
if ext != ".txt": | |
continue | |
os.rename(fname, name + ".sql") | |
# step2 | |
i = name.index("-") | |
left = name[:i] | |
# step3 | |
with open(name + ".sql", "r") as f: | |
contents = f.read().split("\n") | |
with open(name + ".sql", "w") as f: | |
for value in contents: | |
f.write(SQL % (left, value)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment