first commit
This commit is contained in:
12
bot.0.1/Dockerfile
Executable file
12
bot.0.1/Dockerfile
Executable file
@@ -0,0 +1,12 @@
|
||||
FROM python:3.10
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install --upgrade pip \
|
||||
&& pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "telegram_bot.py"]
|
||||
17
bot.0.1/Dockerfile-old-pillow
Executable file
17
bot.0.1/Dockerfile-old-pillow
Executable file
@@ -0,0 +1,17 @@
|
||||
FROM python:3.10-alpine
|
||||
|
||||
RUN adduser -D bot
|
||||
|
||||
USER bot
|
||||
|
||||
WORKDIR /usr/bot
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "telegram_bot.py"]
|
||||
1
bot.0.1/censorship.json
Executable file
1
bot.0.1/censorship.json
Executable file
@@ -0,0 +1 @@
|
||||
["\u0445\u0443\u0439", "\u0431\u043b\u044f\u0442\u044c", "\u043f\u0438\u0437\u0434\u0430"]
|
||||
3
bot.0.1/config.py-exemple
Executable file
3
bot.0.1/config.py-exemple
Executable file
@@ -0,0 +1,3 @@
|
||||
BOT_TOKEN =
|
||||
admin_id =
|
||||
open_weather_API_token =
|
||||
11
bot.0.1/create_bot.py
Executable file
11
bot.0.1/create_bot.py
Executable file
@@ -0,0 +1,11 @@
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.contrib.fsm_storage.memory import MemoryStorage
|
||||
import os
|
||||
|
||||
# РАСКОМЕНТИРУЙ, ЕСЛИ ЗАПУСКАЕШЬ НЕ ЧЕРЕЗ ФАЙЛ "bot_run.bat", НО В ТАКОМ СЛУЧАЕ НЕ ЗАБУДЬ ЗАКОМЕНТИРОВАТЬ "bot = Bot(token=os.getenv("BOT_TOKEN"))" ЭТУ СТРОЧКУ
|
||||
# Уже пофиксил, это можно просто создать переменную окружения (если, что это делается там, где выбираешь интерпретатор)
|
||||
from config import BOT_TOKEN
|
||||
bot = Bot(token=BOT_TOKEN)
|
||||
|
||||
# bot = Bot(token=os.getenv("BOT_TOKEN"))
|
||||
dp = Dispatcher(bot, storage=MemoryStorage())
|
||||
1
bot.0.1/data_base/__init__.py
Executable file
1
bot.0.1/data_base/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from data_base import sqlite_db
|
||||
26
bot.0.1/data_base/sqlite_db.py
Executable file
26
bot.0.1/data_base/sqlite_db.py
Executable file
@@ -0,0 +1,26 @@
|
||||
from create_bot import bot
|
||||
import sqlite3 as sq
|
||||
|
||||
base = None
|
||||
cur = None
|
||||
|
||||
|
||||
def sql_start():
|
||||
global base, cur
|
||||
base = sq.connect("pizza_cool.db")
|
||||
cur = base.cursor()
|
||||
if base:
|
||||
print("Data base connected OK!")
|
||||
base.execute("CREATE TABLE IF NOT EXISTS menu(img TEXT, name TEXT PRIMARY KEY, description TEXT, price TEXT)")
|
||||
base.commit()
|
||||
|
||||
|
||||
async def sql_add_command(state):
|
||||
async with state.proxy() as data:
|
||||
cur.execute("INSERT INTO menu VALUES (?, ?, ?, ?)", tuple(data.values()))
|
||||
base.commit()
|
||||
|
||||
|
||||
async def sql_reade(message):
|
||||
for ret in cur.execute("SELECT * FROM menu").fetchall():
|
||||
await bot.send_photo(message.from_user.id, ret[0], f"\n{ret[1]}\nОписание: {ret[2]}\nЦена: {ret[-1]}")
|
||||
0
bot.0.1/handlers/__init___.py
Executable file
0
bot.0.1/handlers/__init___.py
Executable file
97
bot.0.1/handlers/admin.py
Executable file
97
bot.0.1/handlers/admin.py
Executable file
@@ -0,0 +1,97 @@
|
||||
from aiogram.dispatcher import FSMContext
|
||||
from aiogram.dispatcher.filters.state import State, StatesGroup
|
||||
from aiogram.dispatcher.filters import Text
|
||||
from aiogram import types, Dispatcher
|
||||
from create_bot import bot
|
||||
from data_base import sqlite_db
|
||||
from keybords import button_case_admin
|
||||
|
||||
ID = None
|
||||
|
||||
|
||||
class FSMAdmin(StatesGroup):
|
||||
photo = State()
|
||||
name = State()
|
||||
description = State()
|
||||
price = State()
|
||||
|
||||
|
||||
# Получаем ID текущего модератора
|
||||
async def make_changes_command(message: types.Message):
|
||||
global ID
|
||||
ID = message.from_user.id
|
||||
await bot.send_message(message.from_user.id, f"Что нужно хозяин {message.from_user.first_name} ???", reply_markup=button_case_admin)
|
||||
await message.delete()
|
||||
|
||||
|
||||
# - Начало диалога загрузки нового пункта меню
|
||||
async def cm_start(message: types.Message):
|
||||
if message.from_user.id == ID:
|
||||
await FSMAdmin.photo.set()
|
||||
await message.reply("Загрузи фото")
|
||||
|
||||
|
||||
# Выход из состояний
|
||||
async def cancel_handler(message: types.Message, state: FSMContext):
|
||||
if message.from_user.id == ID:
|
||||
current_state = await state.get_state()
|
||||
if current_state is None:
|
||||
return
|
||||
await state.finish()
|
||||
await message.reply("ОК")
|
||||
|
||||
|
||||
# - Ловим первый ответ
|
||||
async def load_photo(message: types.Message, state: FSMContext):
|
||||
if message.from_user.id == ID:
|
||||
async with state.proxy() as data:
|
||||
data["photo"] = message.photo[0].file_id
|
||||
await FSMAdmin.next()
|
||||
await message.answer("Введи название")
|
||||
|
||||
|
||||
# - Ловим Второй ответ
|
||||
async def load_name(message: types.Message, state: FSMContext):
|
||||
if message.from_user.id == ID:
|
||||
async with state.proxy() as data:
|
||||
data["name"] = message.text
|
||||
await FSMAdmin.next()
|
||||
await message.answer("Введити описание")
|
||||
|
||||
|
||||
# - Ловим третий ответ
|
||||
async def load_description(message: types.Message, state: FSMContext):
|
||||
if message.from_user.id == ID:
|
||||
async with state.proxy() as data:
|
||||
data["description"] = message.text
|
||||
await FSMAdmin.next()
|
||||
await message.answer("Укажи цену")
|
||||
|
||||
|
||||
# - Ловим последний ответ
|
||||
async def load_price(message: types.Message, state: FSMContext):
|
||||
if message.from_user.id == ID:
|
||||
state.proxy()
|
||||
try:
|
||||
float(message.text)
|
||||
except:
|
||||
await FSMAdmin.price.set()
|
||||
await message.reply("Ценa указана не верно")
|
||||
await message.answer("Укажи цену ещё раз")
|
||||
async with state.proxy() as data:
|
||||
data["price"] = float(message.text)
|
||||
|
||||
await sqlite_db.sql_add_command(state)
|
||||
# await message.answer(str(data))
|
||||
await state.finish()
|
||||
|
||||
|
||||
def register_handlers_client(dp: Dispatcher):
|
||||
dp.register_message_handler(cm_start, commands=["Загрузить"], state=None)
|
||||
dp.register_message_handler(cancel_handler, commands=["отмена"], state="*")
|
||||
dp.register_message_handler(cancel_handler, Text(equals="отмена", ignore_case=True), state="*")
|
||||
dp.register_message_handler(load_photo, content_types=["photo"], state=FSMAdmin.photo)
|
||||
dp.register_message_handler(load_name, state=FSMAdmin.name)
|
||||
dp.register_message_handler(load_description, state=FSMAdmin.description)
|
||||
dp.register_message_handler(load_price, state=FSMAdmin.price)
|
||||
dp.register_message_handler(make_changes_command, commands=["moderator"], is_chat_admin=True)
|
||||
139
bot.0.1/handlers/client.py
Executable file
139
bot.0.1/handlers/client.py
Executable file
@@ -0,0 +1,139 @@
|
||||
from aiogram.dispatcher.filters.state import State, StatesGroup
|
||||
from aiogram.dispatcher import FSMContext
|
||||
from aiogram.dispatcher.filters import Text
|
||||
from aiogram import types, Dispatcher
|
||||
from config import open_weather_API_token
|
||||
from keybords import custom_kb_client
|
||||
from data_base import sqlite_db
|
||||
import other_packages
|
||||
from create_bot import bot
|
||||
from asyncio import sleep
|
||||
import datetime
|
||||
import requests
|
||||
import string
|
||||
import json
|
||||
|
||||
|
||||
class FSMWeather(StatesGroup):
|
||||
place = State()
|
||||
|
||||
|
||||
async def cmd_start(message: types.Message):
|
||||
await message.reply("Hi!\nI'm Bot!\nPowered by aiogram.", reply_markup=custom_kb_client)
|
||||
|
||||
|
||||
async def get_coin(message: types.Message):
|
||||
await message.reply(f"{other_packages.print_bitcoin()}\U0001F911")
|
||||
|
||||
|
||||
async def get_weather(message: types.Message):
|
||||
await FSMWeather.place.set()
|
||||
await message.answer("Введите город")
|
||||
|
||||
|
||||
async def cancel_handler(message: types.Message, state: FSMContext):
|
||||
current_state = await state.get_state()
|
||||
if current_state is None:
|
||||
return
|
||||
await state.finish()
|
||||
await message.reply("ОК")
|
||||
|
||||
|
||||
async def place(message: types.Message, state: FSMContext):
|
||||
state.proxy()
|
||||
flag = 1
|
||||
|
||||
code_to_smile = {
|
||||
"Clear": "Ясно \U00002600",
|
||||
"Clouds": "Облачно \U00002601",
|
||||
"Rain": "Дождь \U00002614",
|
||||
"Drizzle": "Дождь \U00002614",
|
||||
"Thunderstorm": "Гроза \U000026A1",
|
||||
"Snow": "Снег \U0001F328",
|
||||
"Mist": "Туман \U0001F32B"
|
||||
}
|
||||
|
||||
while flag == 1:
|
||||
try:
|
||||
r = requests.get(
|
||||
f"https://api.openweathermap.org/data/2.5/weather?q={message.text}&appid={open_weather_API_token}&units=metric"
|
||||
)
|
||||
|
||||
data = r.json()
|
||||
|
||||
city = data["name"]
|
||||
current_weather = data["main"]["temp"]
|
||||
|
||||
weather_description = data["weather"][0]["main"]
|
||||
if weather_description in code_to_smile:
|
||||
wd = code_to_smile[weather_description]
|
||||
else:
|
||||
wd = "Я понятия не имею, что у тебя там творится, выгялни в окно и посмотри!"
|
||||
|
||||
humidity = data["main"]["humidity"]
|
||||
pressure = data["main"]["pressure"]
|
||||
wind = data["wind"]["speed"]
|
||||
sunrise_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunrise"])
|
||||
sunset_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunset"])
|
||||
length_of_the_day = sunset_timestamp - sunrise_timestamp
|
||||
await message.answer(f"***{datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}***\n"
|
||||
f"Погода в городе: {city}\nТемпература: {current_weather}C° {wd}\n"
|
||||
f"Влажность: {humidity}%\nДавление: {pressure} мм.рт.ст\n"
|
||||
f"Ветер: {wind} м/c\nВосход солнца: {sunrise_timestamp}\n"
|
||||
f"Закат солнца: {sunset_timestamp}\nПродолжительность дня: {length_of_the_day}\n"
|
||||
f"***\U0001F389Хорошего дня!\U0001F60B***")
|
||||
|
||||
except:
|
||||
await message.reply("Проверьте название города\U0001F914")
|
||||
break
|
||||
flag = 0
|
||||
await state.finish()
|
||||
|
||||
|
||||
async def pizza_menu_command(message: types.Message):
|
||||
await sqlite_db.sql_reade(message)
|
||||
|
||||
|
||||
async def play_dice(message: types.Message):
|
||||
await bot.send_message(message.from_user.id, f"Привет\U0001F44B {message.from_user.username}! Начинаем игру!!!\U0001F3B2")
|
||||
await sleep(0.5)
|
||||
await bot.send_message(message.from_user.id, "Я буду кидать первым\U0001F60B")
|
||||
await sleep(1)
|
||||
|
||||
bot_data = await bot.send_dice(message.from_user.id)
|
||||
bot_data = bot_data["dice"]["value"]
|
||||
await sleep(4)
|
||||
|
||||
user_data = await bot.send_dice(message.from_user.id)
|
||||
user_data = user_data["dice"]["value"]
|
||||
await sleep(4)
|
||||
|
||||
if bot_data > user_data:
|
||||
await bot.send_message(message.from_user.id, f"Вы проиграли\U0001F972")
|
||||
elif bot_data < user_data:
|
||||
await bot.send_message(message.from_user.id, "\U0001F389Вы победили!!!\U0001F3C6")
|
||||
else:
|
||||
await bot.send_message(message.from_user.id, "Ничья\U0001F609")
|
||||
|
||||
|
||||
# async def name_filter(message: types.Message):
|
||||
# if {i.lower().translate(str.maketrans("", "", string.punctuation)) for i in message.text.split(" ")} \
|
||||
# .intersection(set(json.load(open("name_dict.json")))):
|
||||
# await message.answer(f"Меня зовут Гена!!!")
|
||||
|
||||
|
||||
async def Said_filter(message: types.Message):
|
||||
await message.answer("Вы упоминали Саида, что он в этот раз учудил?")
|
||||
|
||||
|
||||
def register_handlers_client(dp: Dispatcher):
|
||||
dp.register_message_handler(cmd_start, commands=["start"])
|
||||
dp.register_message_handler(get_coin, commands=["bitcoin"])
|
||||
dp.register_message_handler(get_weather, commands=["погода", "weather"], state=None)
|
||||
dp.register_message_handler(cancel_handler, commands=["отмена"], state="*")
|
||||
dp.register_message_handler(cancel_handler, Text(equals="отмена", ignore_case=True), state="*")
|
||||
dp.register_message_handler(place, content_types=["text"], state=FSMWeather.place)
|
||||
dp.register_message_handler(pizza_menu_command, commands=["Меню"])
|
||||
dp.register_message_handler(play_dice, commands=["dice"])
|
||||
dp.register_message_handler(Said_filter, lambda message: "Саид" in message.text) # - интересная конструкция
|
||||
# dp.register_message_handler(name_filter)
|
||||
14
bot.0.1/handlers/other.py
Executable file
14
bot.0.1/handlers/other.py
Executable file
@@ -0,0 +1,14 @@
|
||||
from aiogram import types, Dispatcher
|
||||
import json
|
||||
import string
|
||||
|
||||
|
||||
async def reaction(message: types.Message):
|
||||
if {i.lower().translate(str.maketrans("", "", string.punctuation)) for i in message.text.split(" ")} \
|
||||
.intersection(set(json.load(open("censorship.json")))):
|
||||
await message.reply(f"\U0001F92CМаты запрещены!!!\U0001F621\U0001F621\U0001F621")
|
||||
await message.delete()
|
||||
|
||||
|
||||
def register_handlers_other(dp: Dispatcher):
|
||||
dp.register_message_handler(reaction)
|
||||
2
bot.0.1/keybords/__init__.py
Executable file
2
bot.0.1/keybords/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from keybords.client_kb import custom_kb_client
|
||||
from keybords.admin_kb import button_case_admin
|
||||
8
bot.0.1/keybords/admin_kb.py
Executable file
8
bot.0.1/keybords/admin_kb.py
Executable file
@@ -0,0 +1,8 @@
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
|
||||
|
||||
|
||||
# - кнопки клавиатуры админа
|
||||
button_load = KeyboardButton("/Загрузить")
|
||||
button_delete = KeyboardButton("/Удалить")
|
||||
|
||||
button_case_admin = ReplyKeyboardMarkup(resize_keyboard=True).add(button_load).add(button_delete)
|
||||
14
bot.0.1/keybords/client_kb.py
Executable file
14
bot.0.1/keybords/client_kb.py
Executable file
@@ -0,0 +1,14 @@
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton # , ReplyKeyboardRemove - нужен для удаления клавиатуры
|
||||
|
||||
|
||||
b1 = KeyboardButton("/Start")
|
||||
b2 = KeyboardButton("/bitcoin")
|
||||
b3 = KeyboardButton("%х%у%й%")
|
||||
b4 = KeyboardButton("Поделиться номером", request_contact=True)
|
||||
b5 = KeyboardButton("Отправить где я ", request_location=True)
|
||||
b6 = KeyboardButton("/Меню")
|
||||
b7 = KeyboardButton("/погода")
|
||||
b8 = KeyboardButton("/dice")
|
||||
|
||||
custom_kb_client = ReplyKeyboardMarkup(resize_keyboard=True) # one_time_keyboard=True - для одноразовости клавиатуры
|
||||
custom_kb_client.add(b1).add(b2).insert(b3).insert(b6).row(b7, b4, b5, b8)
|
||||
247
bot.0.1/my_env_project/bin/Activate.ps1
Executable file
247
bot.0.1/my_env_project/bin/Activate.ps1
Executable file
@@ -0,0 +1,247 @@
|
||||
<#
|
||||
.Synopsis
|
||||
Activate a Python virtual environment for the current PowerShell session.
|
||||
|
||||
.Description
|
||||
Pushes the python executable for a virtual environment to the front of the
|
||||
$Env:PATH environment variable and sets the prompt to signify that you are
|
||||
in a Python virtual environment. Makes use of the command line switches as
|
||||
well as the `pyvenv.cfg` file values present in the virtual environment.
|
||||
|
||||
.Parameter VenvDir
|
||||
Path to the directory that contains the virtual environment to activate. The
|
||||
default value for this is the parent of the directory that the Activate.ps1
|
||||
script is located within.
|
||||
|
||||
.Parameter Prompt
|
||||
The prompt prefix to display when this virtual environment is activated. By
|
||||
default, this prompt is the name of the virtual environment folder (VenvDir)
|
||||
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
||||
|
||||
.Example
|
||||
Activate.ps1
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -Verbose
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||
and shows extra information about the activation as it executes.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
||||
Activates the Python virtual environment located in the specified location.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -Prompt "MyPython"
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||
and prefixes the current prompt with the specified string (surrounded in
|
||||
parentheses) while the virtual environment is active.
|
||||
|
||||
.Notes
|
||||
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
||||
execution policy for the user. You can do this by issuing the following PowerShell
|
||||
command:
|
||||
|
||||
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
|
||||
For more information on Execution Policies:
|
||||
https://go.microsoft.com/fwlink/?LinkID=135170
|
||||
|
||||
#>
|
||||
Param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[String]
|
||||
$VenvDir,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[String]
|
||||
$Prompt
|
||||
)
|
||||
|
||||
<# Function declarations --------------------------------------------------- #>
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Remove all shell session elements added by the Activate script, including the
|
||||
addition of the virtual environment's Python executable from the beginning of
|
||||
the PATH variable.
|
||||
|
||||
.Parameter NonDestructive
|
||||
If present, do not remove this function from the global namespace for the
|
||||
session.
|
||||
|
||||
#>
|
||||
function global:deactivate ([switch]$NonDestructive) {
|
||||
# Revert to original values
|
||||
|
||||
# The prior prompt:
|
||||
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
||||
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
||||
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
|
||||
# The prior PYTHONHOME:
|
||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
||||
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
||||
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
||||
}
|
||||
|
||||
# The prior PATH:
|
||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
||||
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
||||
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
||||
}
|
||||
|
||||
# Just remove the VIRTUAL_ENV altogether:
|
||||
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
||||
Remove-Item -Path env:VIRTUAL_ENV
|
||||
}
|
||||
|
||||
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
||||
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
||||
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
||||
}
|
||||
|
||||
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
||||
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
||||
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
||||
}
|
||||
|
||||
# Leave deactivate function in the global namespace if requested:
|
||||
if (-not $NonDestructive) {
|
||||
Remove-Item -Path function:deactivate
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.Description
|
||||
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
||||
given folder, and returns them in a map.
|
||||
|
||||
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
||||
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
||||
then it is considered a `key = value` line. The left hand string is the key,
|
||||
the right hand is the value.
|
||||
|
||||
If the value starts with a `'` or a `"` then the first and last character is
|
||||
stripped from the value before being captured.
|
||||
|
||||
.Parameter ConfigDir
|
||||
Path to the directory that contains the `pyvenv.cfg` file.
|
||||
#>
|
||||
function Get-PyVenvConfig(
|
||||
[String]
|
||||
$ConfigDir
|
||||
) {
|
||||
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
||||
|
||||
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
||||
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
||||
|
||||
# An empty map will be returned if no config file is found.
|
||||
$pyvenvConfig = @{ }
|
||||
|
||||
if ($pyvenvConfigPath) {
|
||||
|
||||
Write-Verbose "File exists, parse `key = value` lines"
|
||||
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
||||
|
||||
$pyvenvConfigContent | ForEach-Object {
|
||||
$keyval = $PSItem -split "\s*=\s*", 2
|
||||
if ($keyval[0] -and $keyval[1]) {
|
||||
$val = $keyval[1]
|
||||
|
||||
# Remove extraneous quotations around a string value.
|
||||
if ("'""".Contains($val.Substring(0, 1))) {
|
||||
$val = $val.Substring(1, $val.Length - 2)
|
||||
}
|
||||
|
||||
$pyvenvConfig[$keyval[0]] = $val
|
||||
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pyvenvConfig
|
||||
}
|
||||
|
||||
|
||||
<# Begin Activate script --------------------------------------------------- #>
|
||||
|
||||
# Determine the containing directory of this script
|
||||
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||
$VenvExecDir = Get-Item -Path $VenvExecPath
|
||||
|
||||
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
||||
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
||||
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
||||
|
||||
# Set values required in priority: CmdLine, ConfigFile, Default
|
||||
# First, get the location of the virtual environment, it might not be
|
||||
# VenvExecDir if specified on the command line.
|
||||
if ($VenvDir) {
|
||||
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
||||
}
|
||||
else {
|
||||
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
||||
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
||||
Write-Verbose "VenvDir=$VenvDir"
|
||||
}
|
||||
|
||||
# Next, read the `pyvenv.cfg` file to determine any required value such
|
||||
# as `prompt`.
|
||||
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
||||
|
||||
# Next, set the prompt from the command line, or the config file, or
|
||||
# just use the name of the virtual environment folder.
|
||||
if ($Prompt) {
|
||||
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
||||
}
|
||||
else {
|
||||
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
||||
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
||||
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
||||
$Prompt = $pyvenvCfg['prompt'];
|
||||
}
|
||||
else {
|
||||
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
||||
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
||||
$Prompt = Split-Path -Path $venvDir -Leaf
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose "Prompt = '$Prompt'"
|
||||
Write-Verbose "VenvDir='$VenvDir'"
|
||||
|
||||
# Deactivate any currently active virtual environment, but leave the
|
||||
# deactivate function in place.
|
||||
deactivate -nondestructive
|
||||
|
||||
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
||||
# that there is an activated venv.
|
||||
$env:VIRTUAL_ENV = $VenvDir
|
||||
|
||||
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
||||
|
||||
Write-Verbose "Setting prompt to '$Prompt'"
|
||||
|
||||
# Set the prompt to include the env name
|
||||
# Make sure _OLD_VIRTUAL_PROMPT is global
|
||||
function global:_OLD_VIRTUAL_PROMPT { "" }
|
||||
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
||||
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
||||
|
||||
function global:prompt {
|
||||
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
||||
_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
||||
}
|
||||
|
||||
# Clear PYTHONHOME
|
||||
if (Test-Path -Path Env:PYTHONHOME) {
|
||||
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
||||
Remove-Item -Path Env:PYTHONHOME
|
||||
}
|
||||
|
||||
# Add the venv to the PATH
|
||||
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
||||
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
||||
69
bot.0.1/my_env_project/bin/activate
Executable file
69
bot.0.1/my_env_project/bin/activate
Executable file
@@ -0,0 +1,69 @@
|
||||
# This file must be used with "source bin/activate" *from bash*
|
||||
# you cannot run it directly
|
||||
|
||||
deactivate () {
|
||||
# reset old environment variables
|
||||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
||||
PATH="${_OLD_VIRTUAL_PATH:-}"
|
||||
export PATH
|
||||
unset _OLD_VIRTUAL_PATH
|
||||
fi
|
||||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
||||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
||||
export PYTHONHOME
|
||||
unset _OLD_VIRTUAL_PYTHONHOME
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
||||
hash -r 2> /dev/null
|
||||
fi
|
||||
|
||||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
||||
PS1="${_OLD_VIRTUAL_PS1:-}"
|
||||
export PS1
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
fi
|
||||
|
||||
unset VIRTUAL_ENV
|
||||
unset VIRTUAL_ENV_PROMPT
|
||||
if [ ! "${1:-}" = "nondestructive" ] ; then
|
||||
# Self destruct!
|
||||
unset -f deactivate
|
||||
fi
|
||||
}
|
||||
|
||||
# unset irrelevant variables
|
||||
deactivate nondestructive
|
||||
|
||||
VIRTUAL_ENV="/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project"
|
||||
export VIRTUAL_ENV
|
||||
|
||||
_OLD_VIRTUAL_PATH="$PATH"
|
||||
PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
export PATH
|
||||
|
||||
# unset PYTHONHOME if set
|
||||
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
||||
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
||||
if [ -n "${PYTHONHOME:-}" ] ; then
|
||||
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
||||
unset PYTHONHOME
|
||||
fi
|
||||
|
||||
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
||||
_OLD_VIRTUAL_PS1="${PS1:-}"
|
||||
PS1="(my_env_project) ${PS1:-}"
|
||||
export PS1
|
||||
VIRTUAL_ENV_PROMPT="(my_env_project) "
|
||||
export VIRTUAL_ENV_PROMPT
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
||||
hash -r 2> /dev/null
|
||||
fi
|
||||
26
bot.0.1/my_env_project/bin/activate.csh
Executable file
26
bot.0.1/my_env_project/bin/activate.csh
Executable file
@@ -0,0 +1,26 @@
|
||||
# This file must be used with "source bin/activate.csh" *from csh*.
|
||||
# You cannot run it directly.
|
||||
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
||||
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
||||
|
||||
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
||||
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
setenv VIRTUAL_ENV "/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project"
|
||||
|
||||
set _OLD_VIRTUAL_PATH="$PATH"
|
||||
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
|
||||
set _OLD_VIRTUAL_PROMPT="$prompt"
|
||||
|
||||
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
||||
set prompt = "(my_env_project) $prompt"
|
||||
setenv VIRTUAL_ENV_PROMPT "(my_env_project) "
|
||||
endif
|
||||
|
||||
alias pydoc python -m pydoc
|
||||
|
||||
rehash
|
||||
66
bot.0.1/my_env_project/bin/activate.fish
Executable file
66
bot.0.1/my_env_project/bin/activate.fish
Executable file
@@ -0,0 +1,66 @@
|
||||
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
||||
# (https://fishshell.com/); you cannot run it directly.
|
||||
|
||||
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
||||
# reset old environment variables
|
||||
if test -n "$_OLD_VIRTUAL_PATH"
|
||||
set -gx PATH $_OLD_VIRTUAL_PATH
|
||||
set -e _OLD_VIRTUAL_PATH
|
||||
end
|
||||
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
||||
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME
|
||||
end
|
||||
|
||||
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
||||
functions -e fish_prompt
|
||||
set -e _OLD_FISH_PROMPT_OVERRIDE
|
||||
functions -c _old_fish_prompt fish_prompt
|
||||
functions -e _old_fish_prompt
|
||||
end
|
||||
|
||||
set -e VIRTUAL_ENV
|
||||
set -e VIRTUAL_ENV_PROMPT
|
||||
if test "$argv[1]" != "nondestructive"
|
||||
# Self-destruct!
|
||||
functions -e deactivate
|
||||
end
|
||||
end
|
||||
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
set -gx VIRTUAL_ENV "/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project"
|
||||
|
||||
set -gx _OLD_VIRTUAL_PATH $PATH
|
||||
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
|
||||
|
||||
# Unset PYTHONHOME if set.
|
||||
if set -q PYTHONHOME
|
||||
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
||||
set -e PYTHONHOME
|
||||
end
|
||||
|
||||
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
||||
# fish uses a function instead of an env var to generate the prompt.
|
||||
|
||||
# Save the current fish_prompt function as the function _old_fish_prompt.
|
||||
functions -c fish_prompt _old_fish_prompt
|
||||
|
||||
# With the original prompt function renamed, we can override with our own.
|
||||
function fish_prompt
|
||||
# Save the return status of the last command.
|
||||
set -l old_status $status
|
||||
|
||||
# Output the venv prompt; color taken from the blue of the Python logo.
|
||||
printf "%s%s%s" (set_color 4B8BBE) "(my_env_project) " (set_color normal)
|
||||
|
||||
# Restore the return status of the previous command.
|
||||
echo "exit $old_status" | .
|
||||
# Output the original/"old" prompt.
|
||||
_old_fish_prompt
|
||||
end
|
||||
|
||||
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
||||
set -gx VIRTUAL_ENV_PROMPT "(my_env_project) "
|
||||
end
|
||||
10
bot.0.1/my_env_project/bin/pip
Executable file
10
bot.0.1/my_env_project/bin/pip
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
'''exec' "/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project/bin/python3" "$0" "$@"
|
||||
' '''
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
10
bot.0.1/my_env_project/bin/pip3
Executable file
10
bot.0.1/my_env_project/bin/pip3
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
'''exec' "/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project/bin/python3" "$0" "$@"
|
||||
' '''
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
10
bot.0.1/my_env_project/bin/pip3.10
Executable file
10
bot.0.1/my_env_project/bin/pip3.10
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
'''exec' "/mnt/archive/alex/work in programs/Python programs/BOT/pythonProject_test_bot/my_env_project/bin/python3" "$0" "$@"
|
||||
' '''
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
3
bot.0.1/my_env_project/pyvenv.cfg
Executable file
3
bot.0.1/my_env_project/pyvenv.cfg
Executable file
@@ -0,0 +1,3 @@
|
||||
home = /usr/bin
|
||||
include-system-site-packages = false
|
||||
version = 3.10.6
|
||||
1
bot.0.1/name_dict.json
Executable file
1
bot.0.1/name_dict.json
Executable file
File diff suppressed because one or more lines are too long
1
bot.0.1/other_packages/__init__.py
Executable file
1
bot.0.1/other_packages/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from other_packages.used_programs.BITCOIN_RUB1 import print_bitcoin
|
||||
@@ -0,0 +1,23 @@
|
||||
import asyncio
|
||||
from BITCOIN_RUB import get_location
|
||||
from aiogram import Bot,Dispatcher, executor
|
||||
from config import BOT_TOKEN
|
||||
import requests
|
||||
|
||||
|
||||
|
||||
bitcoin_USD_STR = get_location(url='https://www.rbc.ru/crypto/currency/btcusd')
|
||||
|
||||
|
||||
API_link = "https://api.telegram.org/bot5066611282:AAF-n8L35t-RhjH9kQbvlbucXt_q8wNQcv8"
|
||||
|
||||
updates = requests.get(API_link + "/getUpdates?offset=-1").json()
|
||||
print(updates)
|
||||
|
||||
message = updates["result"][0]["message"]
|
||||
chat_id = message["from"]["id"]
|
||||
text = message["text"]
|
||||
sent_message = requests.get(API_link + f"/sendMessage?chat_id={chat_id}&text=Привет, ты написал{text}")
|
||||
sent_message = requests.get(API_link + f"/sendMessage?chat_id={chat_id}&text=Привет, курс битка{bitcoin_USD_STR}")
|
||||
|
||||
|
||||
36
bot.0.1/other_packages/intermediate_bots/telegram_bot(типа красивый).py
Executable file
36
bot.0.1/other_packages/intermediate_bots/telegram_bot(типа красивый).py
Executable file
@@ -0,0 +1,36 @@
|
||||
from aiogram import Bot, Dispatcher, executor, types
|
||||
from open_weather_API import
|
||||
from BITCOIN_RUB import print_bitcoin
|
||||
from config import BOT_TOKEN
|
||||
import asyncio
|
||||
import requests
|
||||
|
||||
|
||||
bot = Bot(token=BOT_TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
|
||||
|
||||
@dp.message_handler(commands=['start'])
|
||||
async def cmd_test(message: types.Message):
|
||||
await message.reply("Hi!\nI'm Bot!\nPowered by aiogram.")
|
||||
|
||||
|
||||
@dp.message_handler(commands="bitcoin")
|
||||
async def get_coin(message: types.Message):
|
||||
await message.reply(f"{print_bitcoin()}")
|
||||
|
||||
|
||||
@dp.message_handler(content_types=['text'])
|
||||
async def reaction(message: types.Message):
|
||||
if message.text.lower() == "привет":
|
||||
await message.answer("Здорово!!!")
|
||||
|
||||
elif message.text.lower() == "погода":
|
||||
|
||||
|
||||
else:
|
||||
await message.reply("Моя тебя совсем не понимать")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
executor.start_polling(dp)
|
||||
24
bot.0.1/other_packages/test.py
Executable file
24
bot.0.1/other_packages/test.py
Executable file
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""import json
|
||||
print(json.load(open("censorship.json")))"""
|
||||
|
||||
|
||||
|
||||
"""import string
|
||||
stroka = "&&&&l?.,o$$&&&x"
|
||||
print(stroka.translate(str.maketrans("x", "l", string.punctuation)))
|
||||
# x - что менять l - на что менять string.punctuation - что вовсе удалить
|
||||
# // string.punctuation - это вся пунктуация, то есть удаляется вся пунктуация"""
|
||||
|
||||
|
||||
"""import time
|
||||
print(time.time())"""
|
||||
|
||||
|
||||
"""import datetime
|
||||
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M')) # 2022-04-06 19:34"""
|
||||
28
bot.0.1/other_packages/used_programs/BITCOIN_RUB1.py
Executable file
28
bot.0.1/other_packages/used_programs/BITCOIN_RUB1.py
Executable file
@@ -0,0 +1,28 @@
|
||||
import lxml
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
headers = {
|
||||
'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36'
|
||||
}
|
||||
|
||||
|
||||
def get_bitcoin(url):
|
||||
response = requests.get(url=url, headers=headers)
|
||||
soup = BeautifulSoup(response.text, 'lxml')
|
||||
bitcoin_USD = soup.find('div', class_='chart__subtitle js-chart-value').text.strip()[:10:].strip()
|
||||
bitcoin_USD_STR = f'BTC/USD: ({bitcoin_USD}$)'
|
||||
return bitcoin_USD_STR
|
||||
|
||||
|
||||
def print_bitcoin():
|
||||
bitcoin_USD = get_bitcoin(url='https://www.rbc.ru/crypto/currency/btcusd')
|
||||
return bitcoin_USD
|
||||
|
||||
|
||||
def main():
|
||||
bitcoin_USD_STR = get_bitcoin(url='https://www.rbc.ru/crypto/currency/btcusd')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
26
bot.0.1/other_packages/used_programs/BITCOIN_USD.py
Executable file
26
bot.0.1/other_packages/used_programs/BITCOIN_USD.py
Executable file
@@ -0,0 +1,26 @@
|
||||
import lxml
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
headers = {
|
||||
'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36'
|
||||
}
|
||||
|
||||
def get_location(url):
|
||||
response = requests.get(url=url, headers=headers)
|
||||
soup = BeautifulSoup(response.text, 'lxml')
|
||||
bitcoin_USD = soup.find('div', class_='chart__subtitle js-chart-value').text.strip()[:10:].strip()
|
||||
bitcoin_USD_STR= f'BTC/USD: ({bitcoin_USD}$)'
|
||||
return bitcoin_USD_STR
|
||||
|
||||
def print_bitcoin():
|
||||
bitcoin_USD = get_location(url='https://www.rbc.ru/crypto/currency/btcusd')
|
||||
#print(bitcoin_USD)
|
||||
return bitcoin_USD
|
||||
|
||||
def main():
|
||||
bitcoin_USD_STR = get_location(url='https://www.rbc.ru/crypto/currency/btcusd')
|
||||
print(bitcoin_USD_STR)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
71
bot.0.1/other_packages/used_programs/open_weather_API.py
Executable file
71
bot.0.1/other_packages/used_programs/open_weather_API.py
Executable file
@@ -0,0 +1,71 @@
|
||||
from config import open_weather_API_token
|
||||
from pprint import pprint
|
||||
import datetime
|
||||
import time
|
||||
import requests
|
||||
|
||||
|
||||
def get_weather(city, open_weather_API_token):
|
||||
code_to_smile = {
|
||||
"Clear": "Ясно \U00002600",
|
||||
"Clouds": "Облачно \U00002601",
|
||||
"Rain": "Дождь \U00002614",
|
||||
"Drizzle": "Дождь \U00002614",
|
||||
"Thunderstorm": "Гроза \U000026A1",
|
||||
"Snow": "Снег \U0001F328",
|
||||
"Mist": "Туман \U0001F32B"
|
||||
}
|
||||
|
||||
try:
|
||||
r = requests.get(
|
||||
f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={open_weather_API_token}&units=metric"
|
||||
)
|
||||
|
||||
# days_ago = int(time.time()) - (86400 * (n == 1))
|
||||
# r_2 = requests.get(
|
||||
# f"https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=55.7522&lon=37.6156&dt={days_ago}&appid={open_weather_API_token}&units=metric&lang=ru"
|
||||
# )
|
||||
|
||||
data = r.json()
|
||||
# data_2 = r_2.json()
|
||||
#pprint(data)
|
||||
|
||||
city = data["name"]
|
||||
cur_weather = data["main"]["temp"]
|
||||
|
||||
weather_description = data["weather"][0]["main"]
|
||||
if weather_description in code_to_smile:
|
||||
wd = code_to_smile[weather_description]
|
||||
else:
|
||||
wd = "Я понятия не имею, что у тебя там творится, выгялни в окно и посмотри!"
|
||||
|
||||
humidity = data["main"]["humidity"]
|
||||
pressure = data["main"]["pressure"]
|
||||
wind = data["wind"]["speed"]
|
||||
sunrise_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunrise"])
|
||||
sunset_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunset"])
|
||||
length_of_the_day = sunset_timestamp - sunrise_timestamp
|
||||
print(f"***{datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}***\n"
|
||||
f"Погода в городе: {city}\nТемпература: {cur_weather}C° {wd}\n"
|
||||
f"Влажность: {humidity}%\nДавление: {pressure} мм.рт.ст\n"
|
||||
f"Ветер: {wind} м/c\nВосход солнца: {sunrise_timestamp}\n"
|
||||
f"Закат солнца: {sunset_timestamp}\nПродолжительность дня: {length_of_the_day}\n"
|
||||
f"Хорошего дня!")
|
||||
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
print("Проверьте название города")
|
||||
|
||||
|
||||
# def print_weather(city, open_weather_API_token):
|
||||
# weather = get_weather(city, open_weather_API_token):
|
||||
# return weather
|
||||
|
||||
def main():
|
||||
city = input('Введите город: ')
|
||||
#n = int(input('Сколько дней назад: '))
|
||||
get_weather(city, open_weather_API_token)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
bot.0.1/other_packages/used_programs/to_json/__init__.py
Executable file
0
bot.0.1/other_packages/used_programs/to_json/__init__.py
Executable file
0
bot.0.1/other_packages/used_programs/to_json/censorship.json
Executable file
0
bot.0.1/other_packages/used_programs/to_json/censorship.json
Executable file
3
bot.0.1/other_packages/used_programs/to_json/censorship.txt
Executable file
3
bot.0.1/other_packages/used_programs/to_json/censorship.txt
Executable file
@@ -0,0 +1,3 @@
|
||||
хуй
|
||||
блять
|
||||
пизда
|
||||
1
bot.0.1/other_packages/used_programs/to_json/name_dict.json
Executable file
1
bot.0.1/other_packages/used_programs/to_json/name_dict.json
Executable file
File diff suppressed because one or more lines are too long
1344
bot.0.1/other_packages/used_programs/to_json/name_dict.txt
Executable file
1344
bot.0.1/other_packages/used_programs/to_json/name_dict.txt
Executable file
File diff suppressed because it is too large
Load Diff
17
bot.0.1/other_packages/used_programs/to_json/to_json.py
Executable file
17
bot.0.1/other_packages/used_programs/to_json/to_json.py
Executable file
@@ -0,0 +1,17 @@
|
||||
import json
|
||||
ar = []
|
||||
with open('censorship.txt', encoding='utf-8') as read_file:
|
||||
for i in read_file:
|
||||
n = i.lower().split("\n")[0]
|
||||
if n != "":
|
||||
ar.append(n)
|
||||
with open('censorship.json', "w", encoding='utf-8') as write_file:
|
||||
json.dump(ar, write_file)
|
||||
|
||||
# with open('name_dict.txt', encoding='utf-8') as read_file:
|
||||
# for i in read_file:
|
||||
# n = i.lower().split("\n")[0]
|
||||
# if n != "":
|
||||
# ar.append(n)
|
||||
# with open('name_dict.json', "w", encoding='utf-8') as write_file:
|
||||
# json.dump(ar, write_file)
|
||||
BIN
bot.0.1/pizza_cool.db
Executable file
BIN
bot.0.1/pizza_cool.db
Executable file
Binary file not shown.
40
bot.0.1/requirements.txt
Executable file
40
bot.0.1/requirements.txt
Executable file
@@ -0,0 +1,40 @@
|
||||
aiogram==2.17.1
|
||||
aiohttp==3.8.6
|
||||
aiosignal==1.3.1
|
||||
asttokens==2.4.1
|
||||
async-timeout==4.0.3
|
||||
attrs==23.2.0
|
||||
Babel==2.9.1
|
||||
backcall==0.2.0
|
||||
beautifulsoup4==4.10.0
|
||||
certifi==2024.2.2
|
||||
charset-normalizer==2.0.12
|
||||
colorama==0.4.6
|
||||
decorator==5.1.1
|
||||
executing==2.0.1
|
||||
frozenlist==1.4.1
|
||||
idna==3.6
|
||||
ipython==8.12.3
|
||||
jedi==0.19.1
|
||||
Jinja2==3.0.3
|
||||
lxml==4.8.0
|
||||
MarkupSafe==2.1.5
|
||||
matplotlib-inline==0.1.6
|
||||
multidict==6.0.5
|
||||
numpy==1.23.3
|
||||
parso==0.8.4
|
||||
pickleshare==0.7.5
|
||||
prompt-toolkit==3.0.43
|
||||
pure-eval==0.2.2
|
||||
Pygments==2.17.2
|
||||
pytz==2024.1
|
||||
requests==2.27.1
|
||||
six==1.16.0
|
||||
soupsieve==2.5
|
||||
stack-data==0.6.3
|
||||
tornado==6.2
|
||||
traitlets==5.14.2
|
||||
urllib3==1.26.18
|
||||
wcwidth==0.2.13
|
||||
yarl==1.9.4
|
||||
Pillow==9.0.1
|
||||
21
bot.0.1/telegram_bot.py
Executable file
21
bot.0.1/telegram_bot.py
Executable file
@@ -0,0 +1,21 @@
|
||||
from handlers import client, admin, other
|
||||
from aiogram import executor
|
||||
from create_bot import dp
|
||||
from data_base import sqlite_db
|
||||
|
||||
|
||||
async def on_startup(_):
|
||||
print("Бот вышел в онлайн")
|
||||
sqlite_db.sql_start()
|
||||
|
||||
admin.register_handlers_client(dp)
|
||||
client.register_handlers_client(dp)
|
||||
other.register_handlers_other(dp)
|
||||
|
||||
|
||||
def main():
|
||||
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user