Instantly share code, notes, and snippets.
Created
February 24, 2016 13:56
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save 0xded093/4c5b5a5c9ff646f17e3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: iso-8859-15 -*- | |
################################################################################################################################################################################## | |
# versione con phantomjs - phantomjs --webdriver=4444 --ssl-protocol=any --ssl-ciphers=any --ignore-ssl-errors=true --webdriver-logfile=./ghost.log --webdriver-loglevel=INFO # | |
# http://txt2re.com/index-python.php3?s=40;XLBMAACJ/0sxNjAwNDIAAIeAOAEAAIkEMTQ1OQ==9;5679664040;&-72&-74&58&53&13&8&-84&6&-68&10&2&-87&-88&12&-85&5&-86 # | |
# # | |
# # | |
################################################################################################################################################################################## | |
import os | |
import platform | |
import subprocess | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
import time | |
from datetime import date | |
import getpass | |
import re | |
# avvio PhantomJS | |
sys = platform.system() | |
FNULL = open(os.devnull, 'w') | |
#subprocess.call('./phantomjs --webdriver=4444 --ssl-protocol=any --ssl-ciphers=any --ignore-ssl-errors=true', shell=True) | |
if sys == 'Windows': | |
subprocess.Popen('c:\\phantomjs.exe --webdriver=4444 --ssl-protocol=any --ssl-ciphers=any --ignore-ssl-errors=true', stdout=FNULL, stderr=subprocess.STDOUT, shell=True) | |
pass | |
elif sys == 'Darwin': | |
subprocess.Popen('phantomjs --webdriver=4444 --ssl-protocol=any --ssl-ciphers=any --ignore-ssl-errors=true', stdout=FNULL, stderr=subprocess.STDOUT, shell=True) | |
pass | |
username = raw_input("Username:"); | |
passphrase = getpass.getpass("Password:"); | |
anno = input("Inserisci l'anno:") | |
mese = input("Inserisci il mese:") | |
giorno = input("Inserisci i giorni (separati da virgola):") | |
presidio_com = raw_input("Inserisci il program:") | |
presidio_fas = raw_input("Inserisci la fase:") | |
user_agent = ( | |
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " + | |
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36" | |
) | |
dcap = dict(DesiredCapabilities.PHANTOMJS) | |
dcap["phantomjs.page.settings.userAgent"] = user_agent | |
def Newlines(): | |
time.sleep(1) | |
newline = driver.find_element_by_id("listaRigheOdT_btnNew") | |
newline.click() | |
def Commessa(): | |
time.sleep(1) | |
findcom = driver.find_element_by_id("btnRicercaCommessa") | |
findcom.click() | |
time.sleep(1) | |
searchcom = driver.find_element_by_id("searchCodCommessa") | |
searchcom.send_keys(presidio_com) | |
searchfase = driver.find_element_by_id("searchFase") | |
searchfase.send_keys(presidio_fas) | |
filtro = driver.find_element_by_id("listaCommesse_btnFiltra") | |
filtro.click() | |
time.sleep(1) | |
# trova id con regex | |
src = driver.page_source | |
p = re.compile(ur'(?s)(?<="listaCommesse_Key">).*?(?=</td><td role="gridcell")') | |
id_commessa = re.search(p, src).group() | |
selectcom = driver.find_element_by_id(id_commessa) | |
selectcom.click() | |
time.sleep(1) | |
def Datafunc(): | |
time.sleep(1) | |
selectdata = driver.find_element_by_id("Data") | |
selectdata.clear() | |
selectdata.send_keys(dataita) | |
km = driver.find_element_by_id("KmPercorsi") | |
km.click() | |
def Savefunc(): | |
# fix calcolo ore ####################################### | |
calc_ore = driver.find_element_by_id("LuogoDestinazine") | |
calc_ore.click() | |
######################################################### | |
saveriga = driver.find_element_by_id("btnSalva") | |
saveriga.click() | |
time.sleep(1) | |
#driver.save_screenshot('out.png'); | |
def WeekDay(): | |
time.sleep(1) | |
Newlines() | |
print "Aggiungo riga 1 per il giorno "+dataita+" - feriale" | |
Datafunc() | |
Commessa() | |
inizio = driver.find_element_by_id("tini") | |
inizio.send_keys("00:00") | |
fine = driver.find_element_by_id("tfin") | |
fine.send_keys("09:00") | |
Savefunc() | |
print "OK" | |
Newlines() | |
print "Aggiungo riga 2 per il giorno "+dataita+" - feriale" | |
Datafunc() | |
Commessa() | |
inizio = driver.find_element_by_id("tini") | |
inizio.send_keys("13:00") | |
fine = driver.find_element_by_id("tfin") | |
fine.send_keys("14:00") | |
Savefunc() | |
print "OK" | |
Newlines() | |
print "Aggiungo riga 3 per il giorno "+dataita+" - feriale" | |
Datafunc() | |
Commessa() | |
inizio = driver.find_element_by_id("tini") | |
inizio.send_keys("18:00") | |
fine = driver.find_element_by_id("tfin") | |
fine.send_keys("00:00") | |
Savefunc() | |
print "OK" | |
def WeekendDay(): | |
time.sleep(2) | |
Newlines() | |
print "Aggiungo 8h per il giorno "+dataita+" sulla commessa "+presidio_com+"-"+presidio_fas | |
Datafunc() | |
Commessa() | |
fine = driver.find_element_by_id("hord") | |
fine.clear() | |
fine.send_keys("8") | |
Savefunc() | |
print "OK" | |
time.sleep(1) | |
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.PHANTOMJS.copy()) | |
driver.set_window_size(1600, 900) | |
print "------------------------------------------------" | |
#driver.get("http://repubblica.it") | |
driver.get("https://navisionweb.lutech.it") | |
print "Apro Navision - "+driver.current_url | |
print "------------------------------------------------" | |
#WebDriverWait(driver, 10).until(EC.title_contains("Log On")) | |
# login | |
login = driver.find_element_by_id("UserName") | |
login.send_keys(username) | |
password = driver.find_element_by_id("Password") | |
password.send_keys(passphrase) | |
password.send_keys(Keys.RETURN) | |
# Gestione consuntivazione | |
#WebDriverWait(driver, 10).until(EC.title_contains("Home Page")) | |
menu1 = driver.find_element_by_id("menu1") | |
menu1.click() | |
# nuovo rapportino | |
time.sleep(1) | |
newrap = driver.find_element_by_id("listaOdT_btnNew") | |
newrap.click() | |
for i in giorno: | |
datatoday = date(anno, mese, i) | |
dataita = datatoday.strftime("%d/%m/%y"); | |
WeekendDay() | |
## Cambia stato | |
rapportino = driver.find_element_by_id("OdTNo_h").get_attribute('value') | |
## choose | |
yes = set(['yes','y', 'ye', '']) | |
no = set(['no','n']) | |
print "------------------------------------------------" | |
choice = raw_input("Fatto, vuoi mandare in approvazione? [yes/no]").lower() | |
if choice in yes: | |
goback = driver.find_element_by_id("btnBack") | |
goback.click() | |
time.sleep(1) | |
select_rap = driver.find_element_by_id(rapportino) | |
select_rap.click() | |
approve = driver.find_element_by_id("btn_CambiaStato") | |
approve.click() | |
print "------------------------------------------------" | |
print "Tutte le ore sono state inserite nel "+rapportino+" e sono state mandate in approvazione" | |
elif choice in no: | |
print "------------------------------------------------" | |
print "Tutte le ore sono state inserite nel "+rapportino | |
else: | |
sys.stdout.write("Rispondi con 'yes' or 'no'") | |
## kill phantom | |
#if sys == 'Windows': | |
# subprocess.Popen('Taskkill /F /IM phantomjs.exe', stdout=FNULL, stderr=subprocess.STDOUT, shell=True) | |
# pass | |
#elif sys == 'Darwin': | |
# subprocess.Popen('killall phantomjs', stdout=FNULL, stderr=subprocess.STDOUT, shell=True) | |
# pass | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment