Last active
August 29, 2015 13:57
-
-
Save paulocheque/9725266 to your computer and use it in GitHub Desktop.
Ryanair
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
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
img = Image.open("/Users/paulocheque/Desktop/flag-brazil.jpg") | |
draw = ImageDraw.Draw(img) | |
#font = ImageFont.truetype("sans-serif.ttf", 16) | |
#font = ImageFont.load("arial.pil") | |
font = ImageFont.truetype("arial.ttf", 15) | |
draw.text((0, 0),"Sample Text",(255,255,255),font=font) | |
img.save('flag-brazil-2.jpg') |
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
# coding: utf-8 | |
from datetime import datetime, timedelta | |
from time import sleep | |
from selenium import webdriver | |
from selenium.webdriver.common.action_chains import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.common.exceptions import TimeoutException | |
class RyanairSearch(object): | |
def __init__(self): | |
# self.driver = webdriver.Chrome() # not working tabs | |
self.driver = webdriver.Firefox() | |
def close(self): | |
self.driver.close() | |
def new_tab(self): | |
ActionChains(self.driver).key_down(Keys.COMMAND).send_keys('t').key_up(Keys.COMMAND).perform() | |
def close_current_tab(self): | |
ActionChains(self.driver).key_down(Keys.COMMAND).send_keys('w').key_up(Keys.COMMAND).perform() | |
def new_search(self, from_airport, to_airport, initial_date, final_date): | |
# sleep(0.5) | |
self.new_tab() | |
print('[%s - %s] %s => %s' % (initial_date, final_date, from_airport, to_airport)) | |
self.driver.get('http://www.ryanair.com/') | |
field_from_airport = self.driver.find_element_by_id('flightFrom') | |
field_to_airport = self.driver.find_element_by_id('flightTo') | |
field_initial_date = self.driver.find_element_by_id('departureInput') | |
field_final_date = self.driver.find_element_by_id('arrivalInput') | |
field_from_airport.clear() | |
field_to_airport.clear() | |
field_initial_date.clear() | |
field_final_date.clear() | |
initial_date = datetime.strptime(initial_date, '%d/%m/%Y') + timedelta(days=3) | |
initial_date = initial_date.strftime('%d/%m/%Y') | |
final_date = datetime.strptime(final_date, '%d/%m/%Y') - timedelta(days=3) | |
final_date = final_date.strftime('%d/%m/%Y') | |
field_from_airport.send_keys(from_airport + '\t') | |
field_to_airport.send_keys(to_airport + '\t') | |
field_initial_date.send_keys(initial_date + '\t') | |
field_final_date.send_keys(final_date + '\t') | |
form = self.driver.find_elements_by_xpath("//form[@id='flightBookingForm']")[0] | |
# form.submit() | |
try: | |
WebDriverWait(self.driver, 1).until(EC.alert_is_present(), 'No alerts') | |
alert = self.driver.switch_to_alert() | |
alert.accept() | |
# self.close_current_tab() | |
print('> Sem resultados') | |
except TimeoutException: | |
print('Sucesso!') | |
pass # no alerts in the good search | |
def research(initial_date, final_date, from_airports, to_airports): | |
ryanair = RyanairSearch() | |
from_airports = from_airports.strip().split('\n') | |
from_airports = filter(str, from_airports) | |
from_airports = [a for a in from_airports if not a.startswith('#')] | |
to_airports = to_airports.strip().split('\n') | |
to_airports = filter(str, to_airports) | |
to_airports = [a for a in to_airports if not a.startswith('#')] | |
print('Total de %s combinacoes (%s * %s)' % (len(from_airports) * len(to_airports), len(from_airports), len(to_airports))) | |
for airport1 in from_airports: | |
for airport2 in to_airports: | |
ryanair.new_search(airport1, airport2, initial_date, final_date) | |
################################################################### | |
from_airports = ''' | |
# Belgium | |
Brussels Charleroi | |
Brussels Zaventem | |
# France | |
# Paris Beauvais | |
# # Germany | |
Dusseldorf Weeze | |
Frankfurt Hahn | |
# # Netherlands | |
Eindhoven | |
Maastricht | |
''' | |
to_airports = ''' | |
# Croatia | |
Osijek | |
Pula | |
Rijeka | |
Zadar | |
Cyprus | |
Paphos | |
# Italy | |
Alghero | |
Ancona | |
Milan Bergamo | |
Milan Malpensa T1 | |
Rome Ciampino | |
Rome Fiumicino | |
Trapani | |
Trieste | |
Turin | |
Venice Treviso | |
Pescara | |
# Portugal | |
# Lisbon | |
# Porto | |
# Romania | |
# Bucharest (Otopeni) | |
# Targu Mures | |
# Slovakia | |
# Bratislava | |
# Spain | |
Barcelona El Prat | |
Ibiza | |
Madrid | |
Menorca | |
Palma | |
Valencia | |
# Sweden | |
# Gothenburg City | |
# Malmo | |
# Skelleftea | |
# Stockholm Skavsta | |
# Stockholm Vasteras | |
''' | |
initial_date = '11/04/2014' | |
final_date = '20/04/2014' | |
# research(initial_date, final_date, from_airports, to_airports) | |
################################################################### | |
from_airports = ''' | |
# Belgium | |
Brussels Charleroi | |
Brussels Zaventem | |
# Netherlands | |
Maastricht | |
''' | |
to_airports = ''' | |
# Italy | |
Alghero | |
Ancona | |
Trapani | |
Trieste | |
Venice Treviso | |
Pescara | |
# France | |
Marseille Provence | |
# Spain | |
# Ibiza | |
# Menorca | |
# Palma | |
# Valencia | |
''' | |
initial_date = '11/04/2014' | |
final_date = '20/04/2014' | |
research(initial_date, final_date, from_airports, to_airports) |
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
# coding: utf-8 | |
from datetime import datetime, timedelta | |
from time import sleep | |
import requests | |
class RyanairSearch(object): | |
def new_search(self, from_airport, to_airport, initial_date, final_date): | |
initial_date = datetime.strptime(initial_date, '%d/%m/%Y') + timedelta(days=3) | |
initial_date = initial_date.strftime('%d/%m/%Y') | |
final_date = datetime.strptime(final_date, '%d/%m/%Y') - timedelta(days=3) | |
final_date = final_date.strftime('%d/%m/%Y') | |
url = 'https://www.bookryanair.com/SkySales/booking.aspx?culture=en-gb&lc=en-gb' | |
payload = dict( | |
sector_1_m=initial_date, | |
sector_2_m=final_date, | |
sector1_o=from_airport, | |
sector1_d=to_airport, | |
travel_type='tt1', | |
ADULT=1, CHILD=1, INFANT=1, | |
) | |
r = requests.post(url, data=payload) | |
t = open('teste.html', 'w') | |
t.write(r.content) | |
t.close() | |
# print(r.content) | |
def research(initial_date, final_date, from_airports, to_airports): | |
ryanair = RyanairSearch() | |
from_airports = from_airports.strip().split('\n') | |
from_airports = filter(str, from_airports) | |
from_airports = [a for a in from_airports if not a.startswith('#')] | |
to_airports = to_airports.strip().split('\n') | |
to_airports = filter(str, to_airports) | |
to_airports = [a for a in to_airports if not a.startswith('#')] | |
print('Total de %s combinacoes (%s * %s)' % (len(from_airports) * len(to_airports), len(from_airports), len(to_airports))) | |
for airport1 in from_airports: | |
for airport2 in to_airports: | |
ryanair.new_search(airport1, airport2, initial_date, final_date) | |
return | |
################################################################### | |
from_airports = ''' | |
# Belgium | |
Brussels Charleroi | |
Brussels Zaventem | |
# France | |
# Paris Beauvais | |
# # Germany | |
Dusseldorf Weeze | |
Frankfurt Hahn | |
# # Netherlands | |
Eindhoven | |
Maastricht | |
''' | |
to_airports = ''' | |
# Croatia | |
Osijek | |
Pula | |
Rijeka | |
Zadar | |
Cyprus | |
Paphos | |
# Italy | |
Alghero | |
Ancona | |
Milan Bergamo | |
Milan Malpensa T1 | |
Rome Ciampino | |
Rome Fiumicino | |
Trapani | |
Trieste | |
Turin | |
Venice Treviso | |
Pescara | |
# Portugal | |
# Lisbon | |
# Porto | |
# Romania | |
# Bucharest (Otopeni) | |
# Targu Mures | |
# Slovakia | |
# Bratislava | |
# Spain | |
Barcelona El Prat | |
Ibiza | |
Madrid | |
Menorca | |
Palma | |
Valencia | |
# Sweden | |
# Gothenburg City | |
# Malmo | |
# Skelleftea | |
# Stockholm Skavsta | |
# Stockholm Vasteras | |
''' | |
initial_date = '11/04/2014' | |
final_date = '20/04/2014' | |
# research(initial_date, final_date, from_airports, to_airports) | |
################################################################### | |
from_airports = ''' | |
# Belgium | |
Brussels Charleroi | |
Brussels Zaventem | |
# Netherlands | |
Maastricht | |
''' | |
to_airports = ''' | |
# Italy | |
Alghero | |
Ancona | |
Trapani | |
Trieste | |
Venice Treviso | |
Pescara | |
# France | |
Marseille Provence | |
# Spain | |
# Ibiza | |
# Menorca | |
# Palma | |
# Valencia | |
''' | |
initial_date = '11/04/2014' | |
final_date = '20/04/2014' | |
research(initial_date, final_date, from_airports, to_airports) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Italy airports https://maps.google.com.br/maps?saddr=pisa&daddr=Veneza,+Rep%C3%BAblica+Italiana+to:palermo+to:alghero+to:Ancona,+Rep%C3%BAblica+Italiana+to:Bari,+Rep%C3%BAblica+Italiana+to:Bolonha,+Rep%C3%BAblica+Italiana+to:Brindisi+BR,+Rep%C3%BAblica+Italiana+to:cagliari+to:Cat%C3%A2nia,+Cat%C3%A2nia,+Rep%C3%BAblica+Italiana+to:comiso+to:cuneo+to:genoa+to:lamezia+to:malpensa+to:milan+to:palermo+to:parma+to:perugia+to:pescara+to:roma+to:Trapani,+Rep%C3%BAblica+Italiana+to:trieste+to:Turim,+Rep%C3%BAblica+Italiana&hl=pt-BR&ie=UTF8&ll=41.426253,12.744141&spn=10.606666,19.753418&sll=41.705729,13.139648&sspn=10.561145,19.753418&geocode=FVcomwIdmbeeACmPWfbwmpHVEjHIeISntQ-4qg%3BFU9ftQIde-u7ACmJPdbx2rF-RzEvEJK98Majew%3BFWiZRQIdc-DLACmZ0E6ByegZEzGA2DsjLAQLCg%3BFYDdagIdP_F-ACkFDMV17_HcEjFQi0qfQpiSKw%3BFVaGmQIdQ0jOACnDqUckKoAtEzGsxT9UgFatDw%3BFddlcwIdv3EBASlvjQfz-OhHEzHhCDlqBlRyCA%3BFSfwpgIdGBOtACkLxFHpmNR_RzFBlKRbAXzhog%3BFZgBbAIdAsURASlt7IDJO3pGEzH52gPM984QAQ%3BFSGCVgIdfS-LACmjHI62FTTnEjGxboHPBhUeIA%3BFcdTPAIdYyXmACm1JRV23eITEzHwPMhRYYf-WA%3BFbPFMwIdndXeAClnJ4h0sKMREzE3QxZ5kMEhrA%3BFd1ApQIdjxdzACmnOIHHOGnNEjFH5iYXy2tdEw%3BFZKTpQIdUIKIACmtmtTcUkHTEjEKYoEY8YRqIw%3BFeCGUgIdGNz4AClhHkPED-U_EzEi_Oo5i9mHyA%3BFSZFuAId5PKEACH-fsegVwrxoym3p4R8dWGGRzH-fsegVwrxow%3BFW6_tQId1CyMACnndRI_ScGGRzGNDnTGE83_PA%3BFWiZRQIdc-DLACmZ0E6ByegZEzGA2DsjLAQLCg%3BFc2dqwIdYJedACkvw9RU4WqARzGaNpBcczehAw%3BFT3RkQIdrBG9AClPw1HqjKAuEzH0x0-IKus5zg%3BFV7qhwIdmuvYACl3ZCi5DaYxEzHivyyyiZ64oA%3BFTQ8fwId2He-ACm7jpL5lmEvEzE4bmWTBncPuQ%3BFVIaRAIdck2_AClfkKTWL2IZEzGCNJj5vN7xiw%3BFX-OuAIdNDzSACkz9e3kBmt7RzFQK93UhCRqZg%3BFYa6rwIdLEZ1ACklvhhkEm2IRzG_d5zWA_gDiQ&oq=turim&t=h&mra=ls&z=6