Форум сайта python.su
from django.contrib import admin from django.urls import path # =========================================>>>>>>>>>>>>>> from django.http import HttpResponse # !!! new (01) k = 0 def home(request): global k k += 1 # stroka = "Привет!!! ===> {0}".format(k) return HttpResponse("<h1>{1}</h1><hr> \ <form><input type='submit' value='{0}'> \ </form>".format(stroka, k)) urlpatterns = [ path('admin/', admin.site.urls), path('', home), ]
from django.db import models # Create your models here. from django.contrib import admin from django.utils.html import format_html class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) color_code = models.CharField(max_length=6) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.mycount1 = 0 def colored_name(self): return format_html('<span style="color: #{};">{} {}</span>', self.color_code, self.first_name, self.last_name) def mycounter(self): self.mycount1 += 1 return format_html('<form method="post" action="."> \ <input type="submit" value="жми кнопку"></form><hr> \ <h1 style="color: #{};">{} </h1>', self.color_code, self.mycount1) class PersonAdmin(admin.ModelAdmin): list_display = ('first_name', 'last_name', 'colored_name', 'mycounter')
from django.contrib import admin # Register your models here. from .models import Person, PersonAdmin admin.site.register(Person, PersonAdmin)
from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), ]
mport telepot, time, subprocess def handle(msg): content_type, chat_type, chat_id = telepot.glance(msg) if (content_type == 'text'): command = msg['text'] print ('Got command: %s' % command) if '/0' in command:#В кавычках команда которую мы будем писать в телеграмм. #Можно и слова и по русски но начинать нужно именно с косой палочки p = subprocess.Popen(cmd0, shell=True)#А тут собственно выполняется команда которую #мы задали для переменной "cmd0" bot.sendMessage(chat_id, "Комп не уйдёт в спящий режим")#А это ответ бота в чат. if '/1' in command: p = subprocess.Popen(cmd1, shell=True) bot.sendMessage(chat_id, "Комп уйдёт в спящий режим через одну минуту простоя") if '/off pc' in command: p = subprocess.Popen(shut, shell=True) bot.sendMessage(chat_id, "Выключаю комп") if '/p' in command: p = subprocess.Popen(soundpc, shell=True) bot.sendMessage(chat_id, "Звук на столе") if '/t' in command: p = subprocess.Popen(soundtv, shell=True) bot.sendMessage(chat_id, "Звук на телике") bot = telepot.Bot('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')#Вместо иксов пишем ваш токен cmd0 = 'Powercfg -setactive 6a935962-1964-4f2a-a937-95cd9b8ca616' cmd1 = 'Powercfg -setactive 021d63d0-34a0-4824-8f5a-b83156cba872' shut = 'shutdown -s' soundpc = 'C:\SSD_v3.exe\SSD.exe 7777hidden' soundtv = 'C:\SSD_v3.exe\SSD.exe 7771hidden' bot.message_loop(handle) while 1: time.sleep(20)
users = [271868950] @bot.message_handler(func=lambda message: message.chat.id not in users) def some(message): bot.send_message(message.chat.id, "Sorry")
прямой ход:
import numpy as np
x1=1
x2=0
//веса
w1=0.2
w2=0.4
w3=0.7
w4=0.5
w5=0.3
w6=0.5
w7=0.6
w8=0.9
b1=1
Zpr1=x1*w1+x2*w5+b1
print ("1 нейрон:", Zpr1)
Zpr2=x1*w2+x2*w6+b1
print ("2 нейрон:", Zpr2)
Zpr3=x1*w3+x2*w7+b1
print ("3 нейрон:", Zpr3)
Zpr4=x1*w4+x2*w8+b1
print ("4 нейрон:", Zpr4)
import math
//активационная функция
def sigmoid(x):
return 1 / (1 + math.exp(1)**-x)
Ypr1=sigmoid(Zpr1)
Ypr2=sigmoid(Zpr2)
Ypr3=sigmoid(Zpr3)
Ypr4=sigmoid(Zpr4)
print("Сигмоид 1 нейрона:", Ypr1)
print("Сигмоид 2 нейрона:", Ypr2)
print("Сигмоид 3 нейрона:", Ypr3)
print("Сигмоид 4 нейрона:", Ypr4)
w9 = 0.2
w10 = 0.4
w11 = 0.6
w12 = 0.8
b2=1
Zpr5=x1*w9+x2*w10+b2
Zpr6=x1*w11+x2*w12+b2
b2 = 1
Zv = Ypr1*w9+Ypr2*w10+Ypr3*w11+Ypr4*w12+b2
print ("Zv: ",Zv)
Yv=sigmoid(Zv)
print ("Yv: ",Yv) //общий выход нейросети
обратный ход (проверка):
E=1/2*(1-Yv)**2
print ("Квадратичная функция ошибки: ", E)
EW9=(E/Yv)*(Yv/Zv)*(Zv/w9) //веса выходного слоя
EW10=(E/Yv)*(Yv/Zv)*(Zv/w10)
EW11=(E/Yv)*(Yv/Zv)*(Zv/w11)
EW12=(E/Yv)*(Yv/Zv)*(Zv/w12)
Eb2=(E/Yv)*(Yv/Zv)*(Zv/b2)
print ("E/W9:", EW9)
print ("E/W10:", EW10)
print ("E/W11:", EW11)
print ("E/W12:", EW12)
print ("E/b2:", Eb2)
wn9=w9-0.5*E1W9 //новые веса
wn10=w10-0.5*EW10
wn11=w11-0.5*EW11
wn12=w12-0.5*EW12
Bn2=b2-0.5*Eb2
print ("W9:", wn9)
print ("W10:", wn10)
print ("W11:", wn11)
print ("W12:", wn12)
print ("b2:", Bn2) //биас
EW1=(E/Yv)*(Yv/Zv)*(Zv/w1)
EW2=(E/Yv)*(Yv/Zv)*(Zv/w2)
EW3=(E/Yv)*(Yv/Zv)*(Zv/w3)
EW4=(E/Yv)*(Yv/Zv)*(Zv/w4)
EW5=(E/Yv)*(Yv/Zv)*(Zv/w5)
EW6=(E/Yv)*(Yv/Zv)*(Zv/w6)
EW7=(E/Yv)*(Yv/Zv)*(Zv/w7)
EW8=(E/Yv)*(Yv/Zv)*(Zv/w8)
Eb1=(E/Yv)*(Yv/Zv)*(Zv/b1)
print ("E/W1:", EW1)
print ("E/W2:", EW2)
print ("E/W3:", EW3)
print ("E/W4:", EW4)
print ("E/W5:", EW5)
print ("E/W6:", EW6)
print ("E/W7:", EW7)
print ("E/W8:", EW8)
print ("E/b1:", Eb1)
wn1=w1-0.5*EW1
wn2=w2-0.5*EW2
wn3=w3-0.5*EW3
wn4=w4-0.5*EW4
wn5=w5-0.5*EW5
wn6=w6-0.5*EW6
wn7=w7-0.5*EW7
wn8=w8-0.5*EW8
Bn1=b1-0.5*Eb1
print ("W1:", wn1)
print ("W2:", wn2)
print ("W3:", wn3)
print ("W4:", wn4)
print ("W5:", wn5)
print ("W6:", wn6)
print ("W7:", wn7)
print ("W8:", wn8)
print ("B1:", Bn1)
[code python]
import browsercookie
import requests
cj = browsercookie.firefox()
r=requests.post('https://binomo.com/ru', cookies=cj)
print(r.status_code)[/code]
from concurrent.futures import ThreadPoolExecutor import multiprocessing import time import asyncio class Config(): def __call__(self): while True: print ("config reload") time.sleep(3) class Run(object): def __init__(self, config_file): self.config_file = config_file self.tasks = [] self.pool = ThreadPoolExecutor(max_workers=multiprocessing.cpu_count()) self.loop = asyncio.get_event_loop() async def run_tasks(self): for i in range(0,10): self.tasks += [self.loop.create_task(self.task(i))] self.loop.run_until_complete(self.save_tasks()) async def save_tasks(self): data = await asyncio.gather(*self.tasks) print ("save data from tasks") async def read_config_file_loop(self): await self.loop.run_in_executor(None, self.config_file) async def task(self,i): print ("run task %s" % i ) await asyncio.sleep(10) async def sleep(self): await asyncio.sleep(10) async def run_tasks_loop(self): while True: await self.run_tasks() await self.sleep() def __call__(self): try: asyncio.async(self.read_config_file_loop()) asyncio.async(self.run_tasks_loop()) self.loop.run_forever() except KeyboardInterrupt: pass finally: self.loop.close() config_file = Config() Run(config_file)()
File "/usr/lib64/python3.6/asyncio/base_events.py", line 414, in run_forever
raise RuntimeError('This event loop is already running')
import Config path = "D:\\CODE\\Libs\\settings.ini" #[FTP] FTP_login= Config.get_setting (path, "FTP", "FTP_login") print(FTP_login)
def get_setting(path, section, setting): """ Print out a setting Вывести настройки """ config = get_config(path) value = config.get(section, setting) msg = "{section} {setting} = {value}".format( section=section, setting=setting, value=value ) #print(msg) return value
[FTP] ftp_login = test
import random import hashlib BASE58 = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' def Candidate(): """ Generate a random, well-formed mini private key. """ return('%s%s' % ('S', ''.join( [BASE58[ random.randrange(0,len(BASE58)) ] for i in range(29)]))) def GenerateKeys(numKeys = 10): """ Generate mini private keys and output the mini key as well as the full private key. numKeys is The number of keys to generate, and """ keysGenerated = 0 totalCandidates = 0 while keysGenerated < numKeys: try: cand = Candidate() # Do typo check t = '%s?' % cand # Take one round of SHA256 candHash = hashlib.sha256(t).digest() # Check if the first eight bits of the hash are 0 if candHash[0] == '\x00': privateKey = GetPrivateKey(cand) print('\n%s\nSHA256( ): %s\nsha256(?): %s' % (cand, privateKey, candHash.encode('hex_codec'))) if CheckShortKey(cand): print('Validated.') else: print('Invalid!') keysGenerated += 1 totalCandidates += 1 except KeyboardInterrupt: break print('\n%s: %i\n%s: %i\n%s: %.1f' % ('Keys Generated', keysGenerated, 'Total Candidates', totalCandidates, 'Reject Percentage', 100*(1.0-keysGenerated/float(totalCandidates)))) def GetPrivateKey(shortKey): """ Returns the hexadecimal representation of the private key corresponding to the given short key. """ if CheckShortKey(shortKey): return hashlib.sha256(shortKey).hexdigest() else: print('Typo detected in private key!') return None def CheckShortKey(shortKey): """ Checks for typos in the short key. """ if len(shortKey) != 30: return False t = '%s?' % shortKey tHash = hashlib.sha256(t).digest() # Check to see that first byte is \x00 if tHash[0] == '\x00': return True return False GenerateKeys (1)
fam = input('Введите фамилию: ') if len(fam)<7: fam=fam+fam im = input('Введите имя: ') if len(im)<3: im=im+im ot = input('Введите отчество: ') if len(ot)<8: ot=ot+ot z='#' a = [(fam[0:3]+z+fam[3:5]),(fam[5:6]+z+fam[6:7]+im[0:3]),(ot[0:1]+z+ot[1:5]),(ot[5:8]+z+fam[0:2]),(fam[2:4]+z+fam[4:7])] for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end=' ') print()