Форум сайта python.su
df.to_csv(filename, index=False, mode='a', compression="gzip") pbar.update()
df = dd.read_csv("./genfiles/13_Apr_2022_17_18_04.gz")
conn = sqlite3.connect('genfiles/13.6.2009.db')
import os import sys import json import asyncio import discord from PyQt5 import QtWidgets from discord.ext import commands from asyncqt import QEventLoop, asyncSlot import botDesign with open('./master.json', 'r', encoding='utf-8-sig') as f: data = json.load(f) TOKEN = data["guild"]["TOKEN"] BP = data["guild"]["command_prefix"] intents = discord.Intents.all() bot = commands.Bot(command_prefix=BP, case_insensitive=True, intents=intents) bot.remove_command('help') class ExampleApp(QtWidgets.QMainWindow, botDesign.Ui_MainWindow): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.client = MyDiscordCLient() self.pushBotButton.clicked.connect(self.on_connect_bot) self.pushCogsButton.clicked.connect(self.load_cog) @asyncSlot() async def on_connect_bot(self): await self.client.start(TOKEN) @asyncSlot() async def load_cog(self): for filename in os.listdir("./cogs"): if filename.endswith(".py") and not filename.startswith("_"): bot.load_extension(f"cogs.{filename[:-3]}") print(f'Loaded {filename[:-3]}') class MyDiscordCLient(discord.Client): async def on_ready(self): print('Bot logged discord server.') await self.change_presence(status=discord.Status.online, activity=discord.Game('test')) def main(): app = QtWidgets.QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) window = ExampleApp() window.show() loop.run_forever() if __name__ == '__main__': main()
import discord import audiopath import audioread from discord.ext import commands from time import sleep class Audio(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_voice_state_update(self, member: discord.Member, before, after): vc_before = before.channel vc_after = after.channel if vc_before == vc_after: return if vc_before is None and vc_after is not None: channel = member.voice.channel vc = await channel.connect() sleep(.1) vc.play(discord.FFmpegPCMAudio(audiopath.connect)) with audioread.audio_open(audiopath.connect) as f: # Start Playing sleep(f.duration) await vc.disconnect() elif vc_after is None and vc_before is not None: return else: channel = member.voice.channel vc = await channel.connect() sleep(.1) vc.play(discord.FFmpegPCMAudio(audiopath.connect)) with audioread.audio_open(audiopath.connect) as f: # Start Playing sleep(f.duration) await vc.disconnect() def setup(bot): bot.add_cog(Audio(bot))
import sys import os import re ## Чтение данных с файла (полностью) def read_file_full(): file = open("fileswot.txt") print(file.read() + "\n") file.close() menu() ## Чтение данных с файла (по - строчно) def read_file_line(): file = open("fileswot.txt") print(file.readline()) file.close() menu() ## Перезаписать данные в файл def record_file(): file = open('fileswot.txt', 'w') try: stroka = input('Введите строку для записи в файл: ') file.write(stroka + "\n") finally: file.close() menu() ## Очистка файла def clearing_file(): file = open('fileswot.txt', 'r') os.system(r'nul>fileswot.txt') file.close() menu() ## Дописать данные в файл def record_fileplus(): file = open('fileswot.txt', 'a') try: stroka = input('Введите строку для записи в файл: ') file.write(stroka + "\n") finally: file.close() menu(aut) ## Поиск значений def search_file(): file = open("fileswot.txt", "r") data = file.read() pl = data.count("+") mi = data.count("-") if pl > mi: return ("Use a breakthrough strategy or a transition strategy № 1") menu(aut) elif pl < mi: return ("Use transition strategy № 2 or survival strategy") menu(aut) else: return ("Error - Equal number of values") menu(aut) ## Удаление строки в файле def delstr_file(): n = int(input("Введите номер строки для удаления: ")) with open(r"fileswot.txt", "r") as file: lines = file.readlines() del lines[n] with open(r"fileswot.txt", "w") as file: file.writelines(lines) menu(aut) ## Создание меню на удаление def menu_del(aut): print("1. Безвозвратно удалить данные") print("2. Вернутся в меню") H = (input("Выберите действие: ")) if H == aut[2]: clearing_file() elif H == aut[3]: menu(aut) else: return ("Error - The selected parameter is not in the menu") menu_del(aut) ## Создание меню на чтение def menu_read(aut): print("1. Прочитать информацию полностью") print("2. Прочитать информацию по - строчно") B = (input("Выберите действие: ")) if B == aut[2]: read_file_full() elif B == aut[3]: read_file_line() else: return ("Error - The selected parameter is not in the menu") menu_read(aut) ## Создание меню на выход def menu_exit(aut): print("1. Выйти") print("2. Вернутся в меню") J = (input("Выберите действие: ")) if J == aut[2]: sys.exit(0) elif J == aut[3]: menu(aut) else: return ("Error - The selected parameter is not in the menu") menu_exit(aut) ## Создание меню def menu(aut): print("1. Прочитать информацию с файла") print("2. Записать информацию в файл") print("3. Дописать информацию в файл") print("4. Очистить данные файла") print("5. Удалить строку в файле") print("6. Выполнить поиск по значениям") print("7. Выход из программы") A = (input("Выберите действие: ")) if A == aut[2]: menu_read(aut) elif A == aut[3]: record_file() elif A == aut[4]: record_fileplus() elif A == aut[5]: menu_del() elif A == aut[6]: delstr_file() elif A == aut[7]: search_file() elif A == aut[8]: menu_exit() else: return ("Error - The selected parameter is not in the menu") menu(aut) def autoriz(aut): Login = aut[0] Password = aut[1] a = input("Enter your username: ") if a != Login: return ("Error - Invalid login was entered") else: return ("The login was entered correctly") b = input("Enter your password: ") if b != Password: return ("Error - Invalid password was entered") else: return ("Select the desired action:") menu(aut) ## Авторизация пользователя def main(): aut = ['Admin', 'Qwerty', '1', '2', '3', '4', '5', '6', '7'] Login = aut[0] Password = aut[1] a = input("Enter your username: ") if a != Login: return ("Error - Invalid login was entered") else: print("The login was entered correctly") b = input("Enter your password: ") if b != Password: return ("Error - Invalid password was entered") else: return ("Select the desired action:") menu(aut) if __name__=='__main__': main()
import unittest from unittest import TestCase, main from KP import read_file_full, read_file_line, record_file, clearing_file, record_fileplus, search_file, delstr_file, menu_del, menu_read, menu_exit, autoriz class KP_Test(TestCase): def authorization (self): aut = ['Admin'] self.assertEqual(autoriz(aut), "The login was entered correctly") if __name__ == '__main__': main()
from __builtin__ import True
import win32com.client Outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") Inbox = Outlook.GetDefaultFolder(6)
def get_prime_numbers(n): prime_numbers = [] for number in range(2, n+1): for prime in prime_numbers: if number % prime == 0: break else: prime_numbers.append(number) return prime_numbers
class PrimeNumbers: def __init__(self, n): self.n = n self.number = 0 self.prime = 2 def __iter__(self): self.number = 0 self.prime = 2 return self def __next__(self): self.number += 1 if self.number > self.n: raise StopIteration() for self.number in range(2, self.n+1): if self.number % self.prime != 0: self.prime = self.number return self.prime prime_number_iterator = PrimeNumbers(n=10000) for number in prime_number_iterator: print(number)