Upload files to "/"
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
import requests
|
||||
import string
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
import openpyxl
|
||||
from openpyxl import load_workbook
|
||||
import argparse
|
||||
import os
|
||||
|
||||
def dir_path(path):
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
else:
|
||||
raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path")
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f",type=str,default='redbook.xlsm')
|
||||
parser.add_argument("-w",type=str,default='Sheet1')
|
||||
parser.add_argument("-u")
|
||||
parser.add_argument("-r",type=str,default='R961893')
|
||||
args = parser.parse_args()
|
||||
print(args)
|
||||
|
||||
# Making a GET request
|
||||
uri = 'https://www.redweek.com/posting/' + str(args.r)
|
||||
#uri = 'https://www.redweek.com/posting/' + str(args.r)
|
||||
r = requests.get(uri)
|
||||
# Parsing the HTML
|
||||
soup = BeautifulSoup(r.content, 'html.parser')
|
||||
|
||||
w = soup.find(class_='total__price')
|
||||
x = soup.find('h2', class_='price-value mb-1')
|
||||
z = soup.find(class_='posting-main-price')
|
||||
v = soup.find(class_='posting-feat-unit-view')
|
||||
y = soup.find(class_='posting-main-title')
|
||||
u = soup.find(class_='posting-feat-sleep-bedrooms')
|
||||
u1 = soup.find(class_='posting-feat-sleep-guests')
|
||||
u2 = soup.find(class_='posting-feat-sleep-beds')
|
||||
all_links= soup.findAll('a')
|
||||
|
||||
#from lxml import etree
|
||||
#dom = etree.HTML(str(soup))
|
||||
#PropURL=(dom.xpath('//*[@id="main-content"]/div[2]/div/div[1]/div[1]/section/div[4]/header/h1/a')[0].text)# //*[@id="main-content"]/div[2]/div/div[1]/div[1]/section/div[4]/header/h1/a
|
||||
#PropURLtext=PropURL
|
||||
#PropURL = re.sub('<.*?>','',PropURL)
|
||||
#PropURL = re.sub('(^.*? (?=<)<)','',PropURL)
|
||||
|
||||
|
||||
#PropURL = all_links[65]
|
||||
PropertyName = str(y.text).strip()
|
||||
PricePerNight = str(x.text).strip()
|
||||
ResortView = str(v.text).strip()
|
||||
ResortView = ResortView.replace("View: ", "")
|
||||
Bedrooms = str(u.text).strip()
|
||||
Bedrooms = Bedrooms.replace("\n"," ")
|
||||
SearchBedrooms = re.sub('\D', '', Bedrooms)
|
||||
Sleeps = str(u1.text).strip()
|
||||
Sleeps = Sleeps.replace("\n"," ")
|
||||
SearchSleeps = re.sub('\D', '', Sleeps)
|
||||
SearchView = re.sub(" ",'%20',ResortView)
|
||||
LOS = ''
|
||||
BedDetails = str(u2.text).strip()
|
||||
BedDetails = BedDetails.replace("\n"," ")
|
||||
CheckIn = ""
|
||||
URL = str(y).strip()
|
||||
URL = URL.replace("\n", "")
|
||||
URL = URL.replace("<a href=\"", "<a href=\"https://www.redweek.com")
|
||||
URL2 = URL.replace('<h1 class="posting-main-title"><a href="','')
|
||||
URL2 = (URL2.split('#'))
|
||||
URL3 = URL2[0]
|
||||
URL3 = URL3 + '/timeshare-rentals?bedrooms='+ SearchBedrooms+ '&sleeps=' + SearchSleeps +'&available=1'
|
||||
URL4 = URL3 + '&view='+SearchView
|
||||
|
||||
TotalPrice = str(w).strip()
|
||||
TotalPrice = re.sub('<.*?>', '', TotalPrice)
|
||||
Body1 = str(z.text).strip()
|
||||
for line in Body1.splitlines():
|
||||
# print (line)
|
||||
if line == "\n" : next (line)
|
||||
if line.startswith("Check-in:") :
|
||||
CheckIn = line.replace("Check-in: ","")
|
||||
if line.startswith("Check-out:") :
|
||||
CheckOut = line.replace("Check-out: ","")
|
||||
if re.findall('^\d-', line):
|
||||
LOS = line.strip()
|
||||
if line.startswith("Posted by") :
|
||||
Owner= line.replace("Posted by ","")
|
||||
|
||||
print ('Property: ',PropertyName)
|
||||
print ('Property URL: ',URL3)
|
||||
print ('Bedrooms: ',Bedrooms)
|
||||
print ('Sleeps : ',Sleeps)
|
||||
print ('Nights: ',LOS)
|
||||
print ('BedConfig: ',BedDetails)
|
||||
print ('URL: ',URL)
|
||||
print ('View: ',ResortView)
|
||||
if CheckIn: print ('Check-in: ',CheckIn)
|
||||
if CheckOut: print ('Check-out: ',CheckOut)
|
||||
print ('Price Per Night: ',PricePerNight)
|
||||
print ('TotalPrice: ', TotalPrice)
|
||||
print ('Posted by: ', Owner)
|
||||
|
||||
|
||||
location = str(args.f)
|
||||
import xlwings as xw
|
||||
#wb = xw.Book() # this will create a new workbook
|
||||
#wb = xw.Book('FileName.xlsx') # connect to a file that is open or in the current working directory
|
||||
#wb = xw.Book(r'C:\path\to\file.xlsx') # on Windows: use raw strings to escape backslashes
|
||||
wb = xw.Book(location) # connect to a file that is open or in the current working directory
|
||||
sheet = wb.sheets[args.w]
|
||||
sheet.range('B7').value = PropertyName
|
||||
sheet.range('B8').value = Bedrooms
|
||||
sheet.range('B9').value = Sleeps
|
||||
sheet.range('B10').value = LOS
|
||||
sheet.range('B11').value = BedDetails
|
||||
sheet.range('B12').value = URL
|
||||
sheet.range('B13').value = ResortView
|
||||
sheet.range('B14').value = CheckIn
|
||||
sheet.range('B15').value = CheckOut
|
||||
sheet.range('B16').value = PricePerNight
|
||||
sheet.range('B17').value = TotalPrice
|
||||
sheet.range('B18').value = Owner
|
||||
sheet.range('B34').value = str(PropURL)
|
||||
sheet.range('B35').value = URL4
|
||||
sheet.range('B36').value = URL3
|
||||
#wb.save
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
import requests
|
||||
import string
|
||||
import re
|
||||
import time
|
||||
import xlwings as xw
|
||||
import argparse
|
||||
import os
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
def dir_path(path):
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
else:
|
||||
raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path")
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f",type=str,default='redbook.xlsm')
|
||||
parser.add_argument("-w",type=str,default='Sheet1')
|
||||
parser.add_argument("-u")
|
||||
parser.add_argument("-r",type=str,default='https://www.vrbo.com/rm/321.2072585.2637118/conversation/253dca60-0988-4191-ab23-91f635016e07')
|
||||
parser.add_argument("-username",default='*******')
|
||||
parser.add_argument("-password",default='*******')
|
||||
args = parser.parse_args()
|
||||
print(args)
|
||||
|
||||
gecko_path = 'C:/temp/geckodriver.exe'
|
||||
options = webdriver.firefox.options.Options()
|
||||
options.headless = False
|
||||
driver = webdriver.Firefox(options = options, executable_path = gecko_path)
|
||||
url = args.r
|
||||
driver.get(url)
|
||||
time.sleep(2)
|
||||
username = driver.find_element_by_id("lex-emailAddress")
|
||||
username.send_keys(args.username)
|
||||
password = driver.find_element_by_id("password")
|
||||
password.send_keys(args.password)
|
||||
|
||||
time.sleep(1)
|
||||
driver.find_element_by_id("login").click()
|
||||
time.sleep(4)
|
||||
|
||||
#alert = driver.switch_to.alert
|
||||
#alert.dismiss();
|
||||
|
||||
#try:
|
||||
# element = WebDriverWait(driver, 10).until(
|
||||
# EC.presence_of_element_located((By.CLASS_NAME, "MessageItem MessageItem--payout"))
|
||||
# )
|
||||
#finally:
|
||||
# driver.quit()
|
||||
time.sleep(10)
|
||||
pageSource = driver.page_source
|
||||
fileToWrite = open("page_source.html", "w")
|
||||
fileToWrite.write(pageSource)
|
||||
fileToWrite.close()
|
||||
|
||||
BookingDetailsdates=driver.find_element_by_class_name("BookingDetails__dates")
|
||||
Ledgeritemvalue=driver.find_elements_by_class_name("Ledger-item__value")
|
||||
PaymentSchedule__amount=driver.find_element_by_class_name("PaymentSchedule__amount")
|
||||
NumNightsandGuests=driver.find_element_by_css_selector('.MessageItem--nightAndGuests')
|
||||
adNum=driver.find_element_by_css_selector('.ha-partner-property-selector-property-details')
|
||||
guestName=driver.find_element_by_class_name('h4')
|
||||
Property=driver.find_element_by_class_name('BookingDetails__info')
|
||||
|
||||
EstimatedPayout = Ledgeritemvalue[0].text
|
||||
BookingAmount = Ledgeritemvalue[1].text
|
||||
FullPayment = PaymentSchedule__amount.text
|
||||
Ad = adNum.text
|
||||
Guest = guestName.text
|
||||
Prop = Property.text
|
||||
BookingDetails = str(BookingDetailsdates.text).strip() #Body1 = str(soup.text).strip()
|
||||
for index,line in enumerate(BookingDetails.splitlines()):
|
||||
if line.startswith("Check in") :
|
||||
Checkin=BookingDetails.splitlines()[index+1]
|
||||
if line.startswith("Check out") :
|
||||
Checkout=BookingDetails.splitlines()[index+1]
|
||||
numnights = (NumNightsandGuests.text).strip().splitlines
|
||||
NNights=(NumNightsandGuests.text).strip().splitlines(0)[0]
|
||||
Guests=(NumNightsandGuests.text).strip().splitlines(0)[1]
|
||||
driver.close()
|
||||
|
||||
print ("Estimated Payout: ",EstimatedPayout)
|
||||
print ("Booking amount : ",BookingAmount)
|
||||
print ("Full Payment: ",FullPayment)
|
||||
print ("Ad # : ",Ad)
|
||||
print ("Guest : ",Guest)
|
||||
print ("Property : ",Prop)
|
||||
print ("Check-in: ",Checkin)
|
||||
print ("Check-out: ",Checkout)
|
||||
print ("Num Nights: ",NNights)
|
||||
print ("Guests: ",Guests)
|
||||
|
||||
|
||||
location = str(args.f)
|
||||
wb = xw.Book(location) # connect to a file that is open or in the current working directory
|
||||
sheet = wb.sheets[args.w]
|
||||
sheet.range('F2').value = Guest
|
||||
sheet.range('D7').value = Prop
|
||||
sheet.range('D8').value = Ad
|
||||
sheet.range('D9').value = ''
|
||||
sheet.range('D10').value = Guests
|
||||
sheet.range('D11').value = Checkin
|
||||
sheet.range('D12').value = ''
|
||||
sheet.range('D13').value = Checkout
|
||||
sheet.range('D14').value = EstimatedPayout
|
||||
sheet.range('D15').value = BookingAmount
|
||||
sheet.range('D16').value = FullPayment
|
||||
Reference in New Issue
Block a user