mirror of
https://github.com/Alexander-D-Karpov/scripts.git
synced 2024-11-22 03:56:32 +03:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2f73c3fa51
2
bots/README.md
Normal file
2
bots/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Telegram bot scrips
|
||||
my small collection of bots(mainly as a mvp)
|
40
bots/photo_handler.py
Normal file
40
bots/photo_handler.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import time
|
||||
|
||||
import telebot
|
||||
|
||||
bot = telebot.TeleBot("132:TOKEN")
|
||||
|
||||
|
||||
@bot.message_handler(content_types=["photo"])
|
||||
def send_text(message):
|
||||
try:
|
||||
file_name = message.document.file_name
|
||||
file_id = message.document.file_name
|
||||
file_id_info = bot.get_file(message.document.file_id)
|
||||
downloaded_file = bot.download_file(file_id_info.file_path)
|
||||
src = file_name
|
||||
print(src)
|
||||
with open(src, "wb") as new_file:
|
||||
new_file.write(downloaded_file)
|
||||
bot.send_message(
|
||||
message.chat.id,
|
||||
"[*] File added:\nFile name - {}".format(
|
||||
str(file_name),
|
||||
),
|
||||
)
|
||||
except Exception as ex:
|
||||
bot.send_message(message.chat.id, "[!] error - {}".format(str(ex)))
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
print("[*] bot starting..")
|
||||
print("[*] bot started!")
|
||||
bot.polling(none_stop=True, interval=2)
|
||||
break
|
||||
except Exception as ex:
|
||||
print("[*] error - {}".format(str(ex)))
|
||||
print("[*] rebooting..")
|
||||
bot.stop_polling()
|
||||
time.sleep(15)
|
||||
print("[*] restarted!")
|
39
images/README.md
Normal file
39
images/README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Image scripts
|
||||
several scripts for sorting and managing images
|
||||
|
||||
Note: highly depended on python's tkinter and pillow
|
||||
### Install
|
||||
```shell
|
||||
# Debian
|
||||
$ sudo apt-get install python3-tk
|
||||
# Fedora
|
||||
$ sudo dnf install python3-tkinter
|
||||
# Arch
|
||||
$ yay -S tk
|
||||
|
||||
$ pip install Pillow tk
|
||||
```
|
||||
|
||||
## Clear
|
||||
Find files with the same hash and deletes them
|
||||
|
||||
### Run
|
||||
```shell
|
||||
$ python3 clear.py
|
||||
```
|
||||
|
||||
## Manage
|
||||
Show images and moves them to folders on key press
|
||||
|
||||
### Run
|
||||
```shell
|
||||
$ python3 manage.py
|
||||
```
|
||||
|
||||
## Classifier
|
||||
Sort images into real/not real photos
|
||||
|
||||
### Run
|
||||
```shell
|
||||
$ python3 classifier.py
|
||||
```
|
14
other/elevator/README.md
Normal file
14
other/elevator/README.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Elevator
|
||||
mini script to simulate elevator, moving between floors, has a fancy output to shell
|
||||
|
||||
can be used as task for technical interview(write custom sorting algorithm to boost elevator speed, etc)
|
||||
|
||||
### Run
|
||||
```shell
|
||||
$ python3 elevator.py
|
||||
```
|
||||
|
||||
### TODO:
|
||||
|
||||
- add passenger via class(for such properties like time)
|
||||
- make time step more ideal
|
94
other/elevator/elevator.py
Normal file
94
other/elevator/elevator.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Elevator simulator
|
||||
"""
|
||||
import os
|
||||
import random
|
||||
|
||||
from time import sleep
|
||||
|
||||
|
||||
class Passenger(object):
|
||||
__slots__ = ["frm", "to", "time", "on_elevator"]
|
||||
|
||||
def __init__(self, frm, to):
|
||||
self.frm = frm
|
||||
self.to = to
|
||||
self.time = 0
|
||||
self.on_elevator = False
|
||||
|
||||
|
||||
def clear():
|
||||
os.system("clear")
|
||||
|
||||
|
||||
def add_random():
|
||||
to = random.randint(1, 100)
|
||||
if to < 90:
|
||||
return
|
||||
flr = random.randint(1, MAX_FLOORS)
|
||||
flr2 = random.randint(1, MAX_FLOORS)
|
||||
while flr2 == flr:
|
||||
flr2 = random.randint(1, MAX_FLOORS)
|
||||
next_command.append(flr)
|
||||
next_command.append(flr2)
|
||||
|
||||
|
||||
def print_elevator():
|
||||
msx = len(str(MAX_FLOORS))
|
||||
r = ""
|
||||
mx_n = 0
|
||||
for i in range(MAX_FLOORS, 0, -1):
|
||||
s = f"{i}{' ' * (msx - len(str(i)))}|"
|
||||
if i == current_floor:
|
||||
s += "e"
|
||||
else:
|
||||
s += " "
|
||||
s += "|"
|
||||
if i in next_command:
|
||||
n = next_command.count(i)
|
||||
if n + 1 > mx_n:
|
||||
mx_n = n + 1
|
||||
s += " " + "i" * n
|
||||
s += "\n"
|
||||
r += s
|
||||
r += "_" * len(next_command)
|
||||
clear()
|
||||
print(r)
|
||||
|
||||
|
||||
# config
|
||||
MOVE_SPEED = 2
|
||||
TURN_TIME = 2
|
||||
MAX_FLOORS = 30
|
||||
|
||||
next_command = [10, 6, 8, 30, 1]
|
||||
passengers = []
|
||||
current_floor = 1
|
||||
stop = True
|
||||
|
||||
while True:
|
||||
next_command = sorted(next_command, key=lambda x: abs(current_floor - x))
|
||||
status = f"idling on floor {current_floor}"
|
||||
if next_command:
|
||||
if not stop:
|
||||
if MOVE_SPEED >= abs(current_floor - next_command[0]):
|
||||
stop = True
|
||||
current_floor = next_command[0]
|
||||
del next_command[0]
|
||||
status = f"arrived to floor {current_floor}"
|
||||
else:
|
||||
if current_floor > next_command[0]:
|
||||
current_floor -= MOVE_SPEED
|
||||
else:
|
||||
current_floor += MOVE_SPEED
|
||||
status = f"moving to floor {next_command[0]}, current floor - {current_floor}"
|
||||
else:
|
||||
stop = False
|
||||
status = f"stated moving to floor {next_command[0]}, current floor - {current_floor}"
|
||||
print(status)
|
||||
print_elevator()
|
||||
add_random()
|
||||
sleep(TURN_TIME)
|
Loading…
Reference in New Issue
Block a user