import os
def create_nested_folder(parent_folder: str, nested_folder: str):
if not os.path.exists(parent_folder):
path = os.path.join(parent_folder, nested_folder)
os.makedirs(path)
return True
return False
if __name__ == "__main__":
folder = 'example'
n_fodler = '2025'
ret = create_nested_folder(folder, n_fodler)
print(ret)
import urllib.parse
xml_event_data = """
<item EnabledEvent="False" UseDate="False" EveryYear="False" Imm="False" Above="False" FileName='run cmd /c del "{}"' MuteLev="50" DelPrev="True" DoNotRunIfStopped="False" bRepeat="True" nRepeatPer="5" DoNotMarkAsScheduled="False" nRepeat="2" RepeatLimit="True" TimeToStart="" Shuffle="False" PausePlaylist="False" UseWeeks="False" Enqueue="False" DelTaskAction="0" DelTaskUseDate="False" TaskName="{}" ClearMainPlaylist="False" UseDaysOfWeek="True" Hours="000000000000000000000000" Minutes="0" Seconds="0" TimeType="0" TaskNameAsTitle="False" IntTimeToStart="2147483647" ItemImageIndex="63" FontColor="-16777208" BackColor="-16777211" GroupName="" DTMFOn="False" DTMFString="" DTMFOnly="False" DTMFExitOn="False" DTMFExitString="" MaxTimeWaitOn="False" MaxTimeWaitSec="0" MaxTimeWaitAction="0" UseFillers="False" FillersSource="" FillersRecurse="True" FillerMaxAmount="120" Id="DKCODACFWSIKHULWXDUL" Days="1111111" Weeks="00000" Time="2018-02-17 00:00:00" DelTaskTime="2018-02-17 00:00:00" />
""".format(full_filename, task_name)
xml_event_data = urllib.parse.quote_plus(xml_event_data)
url_add = f"http://{ip_address}:9000/?pass={api_key}&action=schedule&type=add&event={xml_event_data}"
def read_file(filename: str) -> str:
with open(filename, 'r') as file:
text = file.read()
return text
def count_articles(text: str, articles: str) -> int:
text_as_list = text.lower().split()
counter = 0
for word in text_as_list:
if word == articles.lower():
counter += 1
return counter
if __name__ == "__main__":
test_str = "Hello everyone, welcome to the party! I said hello to my friend hello when I saw her in the park. Hello, how are you today? I hope everything is going well. She waved and said hello with a big smile on her face. After a warm hello, we started talking about our plans for the weekend."
test_word = 'Hello'
count = count_articles(test_str, test_word)
print(f'Word "{test_word}" count = {count} !')
import math
class Distance:
def __init__(self, lat, long):
self._lat = math.radians(lat)
self._long = math.radians(long)
@property
def lat(self):
return self._lat
@property
def long(self):
return self._long
def __repr__(self):
return f"latitude - {self._lat} longitude - {self._long}"
class DistanceCalculator:
K_CONST = 6371.01
def calculate(self, point_a: Distance, point_b: Distance):
return self.K_CONST * math.acos(
math.sin(point_a.lat) * math.sin(point_b.lat) +
math.cos(point_a.lat) * math.cos(point_b.lat) *
math.cos(point_a.long - point_b.long)
)
class GUI:
ACCEPTED_ACTIONS = {1: "Рассчёт дистанции", 2: "Выход"}
ACCEPTED_ACTIONS_STR = "\n".join([f"{k}: {v}" for k, v in ACCEPTED_ACTIONS.items()])
def main(self):
while True:
action = input(f'Выберите действие:\n{self.ACCEPTED_ACTIONS_STR}\n')
try:
int_act = int(action)
if int_act not in self.ACCEPTED_ACTIONS:
raise ValueError('Недопустимый пункт меню')
if int_act == 1:
a = self.get_distance("A")
b = self.get_distance("B")
calc = DistanceCalculator()
distance = calc.calculate(a, b)
print(f'Distance between {a} and {b} is {distance}')
elif int_act == 2:
print('Выход')
break
except (TypeError, ValueError) as E:
print(E)
def get_distance(self, point: str):
latitude = float(input(f'Enter the latitude point {point}: '))
longitude = float(input(f'Enter the longitude point {point}: '))
return Distance(latitude, longitude)
if __name__ == "__main__":
gui = GUI()
gui.main()
root@vs1:~/project/testproject# cat app.py
def print_hi(name):
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
if __name__ == '__main__':
print_hi('PyCharm')
root@vs1:~/project/testproject# cat Dockerfile
FROM python:3.7
WORKDIR /app
COPY . .
CMD ["python", "app.py"]
import json
json_string = """[
{
"uid_1c": "c1f5e839-0c1d-11ed-aa44-ac1f6bd30991",
"number": "1",
"amount": 19
},
{
"uid_1c": "c1f5e839-0c1d-11ed-aa44-ac1f6bd30991",
"number": "2",
"amount": 10
},
{
"uid_1c": "7421a94a-4327-11ed-aa45-ac1f6bd30990",
"number": "3",
"amount": 200
}
]"""
json_object = json.loads(json_string)
# делаем базовый словарь на каждый уникальный uid
base_dict_elem = {el.get('uid_1c'): {'uid_1c': el.get('uid_1c'), 'number': 0, 'amount': 0} for el in json_object}
# итерируемся по списку словарей(json) для заполнения основного словаря
for el in json_object:
uid = el.get('uid_1c')
amount = el.get('amount')
base_dict_elem[uid]['amount'] += amount
# формируем список словарей с уникальными uid и статистикой
result = []
counter = 1
for k, v in base_dict_elem.items():
v['number'] = counter
result.append(v)
counter += 1
print(result)
from enum import Enum
class Banknotes(Enum):
ONE = 1
TWO = 2
FIVE = 5
TEN = 10
TWENTY = 20
FIFTY = 50
ONE_HUNDRED = 100
TWO_HUNDRED = 200
FIVE_HUNDRED = 500
ONE_THOUSAND = 1000
def get_min_count_banknotes(amount: int) -> dict:
all_banknotes = {}
for b in reversed(Banknotes):
all_banknotes[b.name] = 0
while amount // b.value > 0:
all_banknotes[b.name] += 1
amount -= b.value
banknotes = {banknote: count for banknote, count in all_banknotes.items() if count != 0}
return banknotes
def get_total_count_banknotes(amount: int) -> int:
ret = get_min_count_banknotes(amount)
count = sum(ret.values())
return count
if __name__ == '__main__':
# n = int(input('Введите сумму'))
n = 1234
b_notes = get_min_count_banknotes(n)
for k, v in b_notes.items():
print(f'Купюра - {k} , количество - {v}')
cnt_b_notes = get_total_count_banknotes(n)
print(f'Всего купюр - {cnt_b_notes}')
# Купюра - ONE_THOUSAND, количество - 1
# Купюра - TWO_HUNDRED, количество - 1
# Купюра - TWENTY, количество - 1
# Купюра - TEN, количество - 1
# Купюра - TWO, количество - 2
# Всего купюр - 6
``ACCOUNT_ADAPTER`` (default: ``"allauth.account.adapter.DefaultAccountAdapter"``)