I
I
Igor Mironov2020-05-14 21:34:09
Python
Igor Mironov, 2020-05-14 21:34:09

Hello, can you rate the code?

This is one of my first codes that I was not asked to do at school, but which is really needed and useful for something.
And I wanted to know how well I coped with my task . The task was
as follows:
directory) and create an archive from it (To the specified directory)
2) It should be able to be used by people who do not know the language
3) It should be readable
And here is the code itself:

import shutil
import time
from datetime import datetime

# Настройки

t = 10
# ↑↑↑ Интервал между бэкапами в минутах ↑↑↑
directory_copy = 'C:\\Users\\MinuteX\\Desktop\\Copy'
# ↑↑↑ Вписать директория откуда копировать папку
directory = 'C:\\Users\\MinuteX\\Downloads\\Paste'
# ↑↑↑ Вписать директорию куда будут копироватся файлы

# ||| ВАЖНО!!! ВСЕ СЛЕШЫ В ДИРЕКТОРИЯХ ДОЛЖНЫ БЫТЬ ДВОЙНЫМИ ↑↑↑

i = 0
t *= 60

while True:

    dt = datetime.today().strftime("%Y-%m-%d-%H.%M.%S")
    name = f"backup_{i}_{dt}"
    direct = f"{directory}\\{name}"

    shutil.make_archive(
                       direct,
                       'zip',
                       directory_copy
                       )

    print("Generate new backup: " + name)

    i += 1

    time.sleep(t)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vladimir Kuts, 2020-05-14
@MinuteX

directory_copy = 'C:\\Users\\MinuteX\\Desktop\\Copy'

use os.path.join if possible use os.path.join once you have already started writing lines with f-formatting - then:
direct = f"{directory}\\{name}"
print("Generate new backup: " + name)
print(f"Generate new backup: {name}")
t = 10
# ↑↑↑ Интервал между бэкапами в минутах ↑↑↑

Maybe add a cron script? And what - will you look at the console for prints all this time? Add logging to the file, or something ...
print("Generate new backup: " + name)

R
Ronald McDonald, 2020-05-14
@Zoominger

What is there to evaluate? It's a little wider than Halloween.
If you remove the extra empty lines and captain's comments, then the code will be one short bunch.

S
Saboteur, 2020-05-15
@saboteur_kiev

Instead of unnecessary comments (by the way, it's better to use only English)
, let's give normal, sane names to variables.
t -> backup_interval
directory_copy -> source_directory
directory -> target_directory
dt -> current_time
What is this?
i ->
t ->
name ->
direct ->
You have to read the entire script to understand. With normal names of variables and functions, the code is read an order of magnitude faster and easier.

S
szafranji, 2020-05-14
@szafranji

Less comments (for such a program) and empty space, and everything is ok.

P
pythonist1234, 2020-05-15
@pythonist1234

Not "slashes", but "slashes".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question