Форум сайта python.su
@bot.message_handler(content_types=['text']) def func(message): if(message.text == "...."): bot.send_message(message.chat.id, text=...) elif(message.text == "..."): bot.reply_to(message, ...") else: ...
@bot.message_handler(commands=["bj"]) def bj(m, res=False): card = 0 bot.send_message(m.chat.id, "Хотите взять карту?") if m.text == "Взять карту": card += random.randint(3, 11) bot.send_message(m.chat.id, f"Пользователь {m.from_user.first_name} взял карту, у него {card}.") if m.text == "Взять ещё одну": card += random.randint(3,11) bot.send_message(m.chat.id, f"У пользователя {m.from_user.first_name} {card} в сумме.") elif card > 21: bot.send_message(m.chat.id, f"Увы... {m.from_user.first_name} у вас {card} в сумме, перебор.") elif card == 21: bot.send_message(m.chat.id, f"Ого, у игрока {m.from_user.first_name} 21 очко!") elif m.text == "Хватит": bot.send_message(m.chat.id, f"Игрок {m.from_user.first_name} решил закончить игру на {card}.") elif m.text == "Хватит": bot.send_message(m.chat.id, f"Игрок {m.from_user.first_name} решил закончить игру не начав")
def _create_archive(self): bt = BytesIO() zip = zipfile.ZipFile(bt, 'w', zipfile.ZIP_DEFLATED) for item in self.file_list: zip.writestr('{}.txt'.format(str(item.Name())), item.Data()) zip.close() bt.seek(0) resulting_file = ResultingFile() resulting_file.SetName('ARCHIVE_NAME') resulting_file.SetData(bt.getvalue()) bt.close() return resulting_file
from tkinter import * window =Tk() window.geometry('800x600') window.resizable(width=0, height=0) window.title("ddd") spinbox1= Spinbox(from_=1, to=2) def start1(): n=int(spinbox1.get()) if n==1: label19=Label(text="Тощина") label20=Label(text="Тепло") label19.place(relx=.65,rely=.05) label20.place(relx=.8,rely=.05) entry1_1= Entry() entry1_1.place(relx=.65,rely=.09) entry1_2= Entry() entry1_2.place(relx=.82,rely=.09) if n==2: label19=Label(text="Тощина ") label20=Label(text="Тепло") label19.place(relx=.65,rely=.05) label20.place(relx=.8,rely=.05) entry1_1= Entry() entry1_1.place(relx=.65,rely=.09) entry1_2= Entry() entry1_2.place(relx=.82,rely=.09) entry2_1= Entry() entry2_1.place(relx=.65,rely=.14) entry2_2= Entry() entry2_2.place(relx=.82,rely=.14) spinbox1.pack() button=Button(command=start1) button.pack() window.mainloop
async def browse_node(node): try: children = await node.get_children() for child in children: ch_name = await child.read_browse_name() print('Child: ', ch_name.Name) await browse_node(child) except Exception: print('browsing failed') async def connect(url): async with Client(url=url) as client: root = client.nodes.root qn = await root.read_browse_name() print('Root name: ', qn.Name) await browse_node(root) print('Children of root are: ', await root.get_children())
import os import matplotlib.pyplot as plt def get_size_format(b, factor=1024, suffix="B"): for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: if b < factor: return f"{b:.2f}{unit}{suffix}" b /= factor return f"{b:.2f}Y{suffix}" def get_directory_size(directory): total = 0 try: for entry in os.scandir(directory): if entry.is_file(): total += entry.stat().st_size elif entry.is_dir(): total += get_directory_size(entry.path) except NotADirectoryError: return os.path.getsize(directory) except PermissionError: return 0 return total def plot_pie(sizes, names): plt.pie(sizes, labels=names, autopct=lambda pct: f"{pct:.2f}%") plt.title("Размеры подкаталогов и файлов") plt.show() folder_path = 'E:\IPTV\__Готовые m3u' directory_sizes = [] names = [] for directory in os.listdir(folder_path): directory = os.path.join(folder_path, directory) directory_size = get_directory_size(directory) if directory_size == 0: continue directory_sizes.append(directory_size) names.append(os.path.basename(directory) + ": " + get_size_format(directory_size)) print("Общий размер каталога:", get_size_format(sum(directory_sizes))) plot_pie(directory_sizes, names)
import os from flask import Flask, request from werkzeug.exceptions import BadRequest app = Flask(__name__) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) DATA_DIR = os.path.join(BASE_DIR, "data") def build_query(it, teg, znachenie): res = map(lambda v: v.strip(), it) if teg == "filter": res = filter(lambda v, txt=znachenie: txt in v, res) if teg == "map": arg = int(znachenie) res = map(lambda v, idx=arg: v.split(" ")[idx], res) if teg == "unique": res = set(res) if teg == "sort": reverse = znachenie == "desc" res = sorted(res, reverse=reverse) if teg == "limit": arg = int(znachenie) res = list(res)[:arg] return res @app.route("/perform_query") def perform_query(): try: teg1 = request.args["teg1"] teg2 = request.args["teg2"] znachenie1 = request.args["znachenie1"] znachenie2 = request.args["znachenie2"] file_name = request.args["file_name"] except KeyError: raise BadRequest file_path = os.path.join(DATA_DIR, file_name) if not os.path.exists(file_path): return BadRequest(description=f"{file_name} was not found") with open(file_path) as last: res = build_query(last, teg1, znachenie1) res = build_query(res, teg2, znachenie2) content = '\n'.join(res) print(content) return app.response_class(content, content_type="text/plain") if __name__ == '__main__': app.run(debug=True)
new_users = [ {'new_username': 'admin1', 'new_code': 'pass1'}, {'new_username': 'admin2', 'new_code': 'pass2'}, {'new_username': 'admin3', 'new_code': 'pass3'} ] @app.route("/") @app.route("/login", methods=['POST', 'GET']) def login(): if current_user.is_authenticated: return redirect(url_for('booking')) form = LoginForm() if form.validate_on_submit(): new_user = [a for a in new_users if a["new_username"] == form.new_username.data and a["new_code"] == form.new_code.data] if new_user: login_user(new_user) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('login')) else: flash('Login Unsuccessful. Please check your name and the code', 'danger') return redirect(url_for('login')) return render_template('login.html', title='Login', form=form)
<?php require_once(DIR . '/../../config.php'); require_once($CFG->dirroot . '/local/tokenize/classes/forms/tokenization.php'); $PAGE->set_url(new moodle_url('/local/tokenize/tokenization.php')); $PAGE->set_context(\context_system::instance()); $PAGE->set_title(get_string('TOKENIZATOR', 'local_tokenize')); $mform= new tokenization(); echo $OUTPUT->header(); if ($mform->is_cancelled()) { //Handle form cancel operation, if cancel button is present on form } else if ($fromform = $mform->get_data()) { //In this case you process validated data. $mform->get_data() returns data posted in form. $name = $mform->get_new_filename('userfile'); echo $name. '<br>'; $content = $mform->get_file_content('userfile'); //echo $content; var_dump($content); $morgot_link = "http://localhost/diplom/local/tokenize/morgot.py?someamountoftext=" . $content; $morgot_data = file_get_contents($morgot_link); echo $morgot_data; } else { // this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed // or on the first display of the form. //displays the form $mform->display(); } echo $OUTPUT->footer();
#!C:\Users\HP\AppData\Local\Programs\Python\Python310-32\python.exe import os import urllib.parse import nltk query_dict = urllib.parse.parse_qs(os.environ['QUERY_STRING']) input_something = str(query_dict['someamountoftext'])[2: -2] def tknz_wrd(someamountoftext): return(nltk.word_tokenize(someamountoftext)) print("Content-Type: text/html\n") print (tknz_wrd(input_something))