From f3b26d3ab7147138d5ffd4bbe743e5105c986925 Mon Sep 17 00:00:00 2001 From: chr243 Date: Tue, 28 Jun 2016 19:55:15 +0200 Subject: [PATCH] first upload to git things i've written while learning python --- 27/selenium/olxbot.py | 49 +++++++++++++++++++++++++++++++++++ 27/sockety/klient.py | 12 +++++++++ 27/sockety/serwer.py | 17 ++++++++++++ 27/sockety/skaner.py | 30 +++++++++++++++++++++ 27/urllib2/szukajka googla.py | 11 ++++++++ 27/urllib2/tytul po isbn.py | 21 +++++++++++++++ 35/sockety/skaner35.py | 30 +++++++++++++++++++++ 7 files changed, 170 insertions(+) create mode 100644 27/selenium/olxbot.py create mode 100644 27/sockety/klient.py create mode 100644 27/sockety/serwer.py create mode 100644 27/sockety/skaner.py create mode 100644 27/urllib2/szukajka googla.py create mode 100644 27/urllib2/tytul po isbn.py create mode 100644 35/sockety/skaner35.py diff --git a/27/selenium/olxbot.py b/27/selenium/olxbot.py new file mode 100644 index 0000000..a5cfc25 --- /dev/null +++ b/27/selenium/olxbot.py @@ -0,0 +1,49 @@ +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +import time + + +fantom = 'path/to/phantomjs.exe' + +def kradnij(strona): + driver = webdriver.PhantomJS(fantom, service_args=['--load-images=no']) + driver.set_window_size(1024, 768) + driver.get("https://olx.pl/praca/?page=" + str(strona)) + ogloszenie = 2 + while 1: + try: + driver.find_element_by_xpath('//tbody/tr[' + str(ogloszenie) + ']/td/article/div[1]/h3/a/strong').click() + except: + print 'Pomijam ogloszenie.' + try: + driver.find_element_by_xpath('//*[@id="contact_methods"]/li').click() + time.sleep(5) + numer = driver.find_element_by_xpath('//*[@id="contact_methods"]/li').text + kategoria = driver.find_element_by_xpath('//tbody/tr/td[2]/ul/li[3]/a').text + nazwaogloszenia = driver.find_element_by_xpath('//div[1]/div[1]/div[1]/div[1]/h1').text + lokalizacja = driver.find_element_by_xpath('//div[1]/div[1]/div[1]/div[1]/p/span/span[2]/strong').text + imie = driver.find_element_by_xpath('//div[1]/div[2]/p/span[1]').text + numer = driver.find_element_by_xpath('//*[@id="contact_methods"]/li').text + wpis = imie + ' ### ' + numer + ' ### ' + lokalizacja + ' ### ' + kategoria + ' ### ' + nazwaogloszenia + print str(wpis) + try: + db = open('bazaolx', 'w') + db.write(wpis) + db.close() + print 'ok' + except: + print 'problem z zapisywaniem' + except: + print 'Brak numeru, lece dalej\n' + #driver.save_screenshot('screen.png') + if ogloszenie >= 43: + ogloszenie = 2 + strona += 1 + print 'Zmiana strony.' + driver.get('http://olx.pl/praca/?page=' + str(strona)) + else: + ogloszenie += 1 + driver.back() + + +kradnij(4) diff --git a/27/sockety/klient.py b/27/sockety/klient.py new file mode 100644 index 0000000..33a1b65 --- /dev/null +++ b/27/sockety/klient.py @@ -0,0 +1,12 @@ +import socket +import SendKeys + + +host = '127.0.0.1' +port = 8118 + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +s.connect((host, port)) +s.send('aaa bbb ccc') +print 'Wyslano' diff --git a/27/sockety/serwer.py b/27/sockety/serwer.py new file mode 100644 index 0000000..1910924 --- /dev/null +++ b/27/sockety/serwer.py @@ -0,0 +1,17 @@ +import socket +import SendKeys + +password = 'aaa' +host = '' +port = 8122 + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.bind((host, port)) +s.listen(5) +print 'running' + +while 1: + client, address = s.accept() + data = client.recv(1024) + if data.split(' ')[0] == password: + print data.split(' ')[1:] diff --git a/27/sockety/skaner.py b/27/sockety/skaner.py new file mode 100644 index 0000000..18f4e7e --- /dev/null +++ b/27/sockety/skaner.py @@ -0,0 +1,30 @@ +import socket +maska_sieci = '192.168.0.' + + +def skan(i): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.01) + s.connect((maska_sieci + str(i), 135)) + ip = maska_sieci + str(i) + print ip + ' - online:' + skan_portow(ip) + except: + pass + +def skan_portow(ip): + for n in range(1,1024): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.01) + s.connect((ip, n)) + print n + except: + pass + + +print 'Skanuje:' +for i in range(0,255): + skan(i) +print 'Koniec skanowania.' diff --git a/27/urllib2/szukajka googla.py b/27/urllib2/szukajka googla.py new file mode 100644 index 0000000..9672646 --- /dev/null +++ b/27/urllib2/szukajka googla.py @@ -0,0 +1,11 @@ +import urllib2 + +headers = {'User-agent' : 'Mozilla/5.0'} +req = urllib2.Request('https://www.google.pl/search?q=chomikuj+otchlan+pdf&ie=&oe=', None, headers) +html = urllib2.urlopen(req).read() +with open('pliknowy.txt', 'a') as plik: + for line in html: + plik.write(line) +''' +%3Dcache <- po tym jest link do chomika +''' diff --git a/27/urllib2/tytul po isbn.py b/27/urllib2/tytul po isbn.py new file mode 100644 index 0000000..0baad0e --- /dev/null +++ b/27/urllib2/tytul po isbn.py @@ -0,0 +1,21 @@ +import urllib2 +import androidhelper + +droid = androidhelper.Android() + + +kodkreskowy = droid.scanBarcode() +isbn = int(kodkreskowy['result']['SCAN_RESULT']) +kod = urllib2.urlopen('http://katalogi.bn.org.pl/iii/encore/search/C__S' + isbn + '__Orightresult__U?lang=pol&suite=cobalt') + +for line in kod: + if 'onerror' in line: + y = line.split('="') + z = y[2].split('"') + c = z[0].split(';') + x = c[0].split('/') + tytul = x[0] + x[1] + print tytul + +url = 'https://www.google.pl/search?q=chomikuj+' + tytul + '+pdf&ie=&oe=' +droid.startAtivity('android.intent.action.VIEW', url) diff --git a/35/sockety/skaner35.py b/35/sockety/skaner35.py new file mode 100644 index 0000000..50b3ea2 --- /dev/null +++ b/35/sockety/skaner35.py @@ -0,0 +1,30 @@ +import socket +maska_sieci = '192.168.0.' + + +def skan(i): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.01) + s.connect((maska_sieci + str(i), 135)) + ip = maska_sieci + str(i) + print(ip + ' - online:') + skan_portow(ip) + except: + pass + +def skan_portow(ip): + for n in range(1,1024): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(0.01) + s.connect((ip, n)) + print(n) + except: + pass + + +print('Skanuje:') +for i in range(0,255): + skan(i) +print('Koniec skanowania.')