Skip to content

Commit

Permalink
Added custom file rename chronology indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
goorkamateusz committed Jan 16, 2021
1 parent f4a05af commit 01a298b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PustePytania/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Naglowek pliku
file_head = "Plik wygenerowany na podstawie ankiet z Discorda"

# Nazwa pliku wyjsciowego
EXAM_NAME = "TestyChronologicznie"
28 changes: 28 additions & 0 deletions PustePytania/RenameFiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import Config

class RenameFiles:
""" Rename output files """

@staticmethod
def rename(exam_name: str):
""" public static """
exam_files = list(os.listdir("out"))

def name_filter(name: str):
return Config.EXAM_NAME not in name and os.path.isfile(f"out/{name}")

def sort_key(name: str):
return int(name.replace("exam-", "").replace(".txt", ""))

num_of_files_in_dir = len(exam_files)
exam_files = list(filter(name_filter, exam_files))
file_num = num_of_files_in_dir - len(exam_files) + 1
exam_files.sort(key = sort_key, reverse=True)

for exam_file in exam_files:
os.rename(f"out/{exam_file}", f"out/{exam_name}-{file_num}.txt")
file_num += 1

if __name__ == "__main__":
RenameFiles.rename(Config.EXAM_NAME)
4 changes: 4 additions & 0 deletions PustePytania/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from discord.ext import commands
import Config
from PustePytania import *
from RenameFiles import *

if __name__ == "__main__":

Expand All @@ -21,12 +22,15 @@ async def on_ready():
async def readchannel(ctx):
""" Czyta i przetwarza historie z kanału, na którym został wywołany. """
await PustePytania.readchannel( ctx, Config.file_head )
RenameFiles.rename(Config.EXAM_NAME)


@bot.command(name="readlast")
async def readlast(ctx):
""" Czyta i przetwarza wiadomości do najświeższej reakcji 🆕"""
await PustePytania.readchannel( ctx, Config.file_head, 1 )
RenameFiles.rename(Config.EXAM_NAME)


# Uruchomienie bota
bot.run(Config.TOKEN)

0 comments on commit 01a298b

Please sign in to comment.