Форум сайта python.su
from grab import Grab import threading import random import time def test_proxy(proxy): grab = Grab(url = 'https://api.ipify.org?format=json', connect_timeout = 10, proxy = proxy, proxy_type = 'socks5') try: grab.request() print(grab.response.unicode_body()) except Exception as e: print(e) proxyList = Grab().go('http://api.best-proxies.ru/feeds/proxylist.txt?key=01YvxflHzjs4eyNvDhtrdeoU&type=socks5&limit=0').unicode_body().split('\r\n') for i in range(50): threading.Thread(target= test_proxy, args= [random.choice(proxyList)]).start() while threading.active_count() > 1: time.sleep(1)
from grab import Grab import threading import random import time def test_proxy(proxy): grab = Grab(url = 'https://api.ipify.org?format=json', connect_timeout = 10, proxy = proxy, proxy_type = 'http') try: grab.request() print(grab.response.unicode_body()) except Exception as e: print(e) proxyList = Grab().go('http://api.best-proxies.ru/feeds/proxylist.txt?key=01YvxflHzjs4eyNvDhtrdeoU&type=https&limit=0').unicode_body().split('\r\n') for i in range(50): threading.Thread(target= test_proxy, args= [random.choice(proxyList)]).start() while threading.active_count() > 1: time.sleep(1)
class Place(models.Model): place_id = models.AutoField(primary_key=True) place = models.CharField(max_length=10, null=False) class Host(models.Model): host_id = models.AutoField(primary_key=True) place = models.ForeignKey('Place', on_delete=models.PROTECT) host = models.CharField(max_length=30, blank=False, null=False) class Device(models.Model): device_id = models.AutoField(primary_key=True) host = models.ForeignKey('Host', on_delete=models.PROTECT) model = models.ForeignKey('Model', on_delete=models.PROTECT) ip = models.GenericIPAddressField(null=True) name = models.CharField(max_length=30, blank=False, null=False)
class DeviceAdmin(admin.ModelAdmin): list_display=('host', 'name', 'model', 'ip', 'slots') list_filter = ( 'host__place', ('host', admin.RelatedOnlyFieldListFilter), ('model', admin.RelatedOnlyFieldListFilter), ) def host_place(self, instance): return instance.host.place host_location.short_description = 'Place' host_location.admin_order_field = 'host__place' admin.site.register(Device, DeviceAdmin)
import cv2 from PIL import Image from pytesser import * from time import sleep IMAGE_FILE = 'something.jpg' while True: # save image from webcam img = cv2.VideoCapture(0).read()[1] cv2.imwrite(IMAGE_FILE, img) # load image img = Image.open(IMAGE_FILE) # detect words in image words = image_to_string(img).strip() print words sleep(5)
from PyQt4 import QtGui class Board(QtGui.QWidget): def __init__(self): super(Board, self).__init__() self.all_notification = [] self.scroll_layout = QtGui.QVBoxLayout() self.scroll_widget = QtGui.QWidget() self.scroll_widget.setLayout(self.scroll_layout) self.scroll_area = QtGui.QScrollArea() self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.scroll_widget) self.main_layout = QtGui.QVBoxLayout() self.main_layout.addWidget(self.scroll_area) self.setLayout(self.main_layout) self.default_label = QtGui.QLabel( '{}Уведомлений нет{}'.format(' ' * 14, ' ' * 14) ) self.scroll_layout.addWidget(self.default_label) self.scroll_layout.addStretch(0) self.all_notification.append(self.default_label) def add_notification(self, massage): self.all_notification[0].hide() notification = QtGui.QLabel(massage) self.scroll_layout.addWidget(notification) self.all_notification.append(notification) self._remove_stretch() self.scroll_layout.addStretch(0) def _remove_stretch(self): for i in reversed(range(self.scroll_layout.count())): item = self.scroll_layout.itemAt(i) if isinstance(item, QtGui.QSpacerItem): self.scroll_layout.removeItem(item) return app = QtGui.QApplication([]) w = QtGui.QWidget() l = QtGui.QHBoxLayout() w.setLayout(l) but = QtGui.QPushButton('Добавить сообщение') l.addWidget(but) b = Board() l.addWidget(b) but.clicked.connect(lambda: b.add_notification('wefew' * (b.scroll_layout.count() + 2))) w.show() app.exec_()
# coding: utf8 import subprocess import time cmd1 = 'gnome-terminal -e "python /home/bmf/test.py"' b = subprocess.Popen(cmd1, shell=True) print b.poll() time.sleep(3) print(b.poll()) time.sleep(2) print(b.poll()) print("start waiting") b.wait() print("stop waiting") time.sleep(1) print(b.poll())
import time i = 50 while i > 0: print 'test' time.sleep(1) i = i - 1
tn = telnetlib.Telnet("10.251.58.18", 23) tn.read_until(b"login:",5) tn.write(b"admin\n") tn.read_until(b"Password:",5) tn.write(b"admin\n") # Здесь я хочу организовать ветвление: # if tn.read_until(b"admin@RGR>",5) # then tn.write(b"show configuration | display set\n ") # elseif tn.read_until(b"opeator#M10#>",5) # then tn.write(b"show running-config\n ") # но не знаю как. s1=tn.read_until(b"admin@RGR>",50) tn.close(); sys.stdout = open('10.251.58.18.txt', 'w') print(s1)
train=pd.read_csv('train.csv') x = train.iloc[:, 0:12] y = train.iloc[:, 13] from sklearn.cross_validation import train_test_split x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)