Commit 7c1bd156 authored by Melroy van den Berg's avatar Melroy van den Berg

Add seperate marktplaats module

parent a37c51ea
"""
Marktplaats specific methods, an extenstion of the MozRepl class
"""
from mozrepl import MozRepl
class Marktplaats(MozRepl):
def __init__(self):
super(Marktplaats, self).__init__()
def check_marktplaats_login(self):
"""
Verifiy if user is already logged-in
"""
# Open marktplaats
self.open_url("https://www.marktplaats.nl")
# Switch to the document active tab (web-page)
self.switch_to_content()
# From this moment on, the write_data/read_data calls COULD be important to
# run in context of content (enter(content)), use read_data(true) when applicable and check the valid flag
# Check logout url availability
self.write_data(b"function checkLogin(){for(var n=0,t=document.links.length;n<t;n++)if(document.links[n].href.startsWith(\"https://auth.marktplaats.nl/accounts/authentication/logout\"))return 1;return null}")
self.skip_data()
# Execute the javascript function above
self.write_data(b"checkLogin()")
# 1 is logout url found, 0 is not found
(loggedin, valid) = self.read_data()
if loggedin == b'1':
print ("Already logged in at Marktplaats.")
#self.create_popup("U bent reeds ingelogd in Marktplaats.")
return 1
else:
print ("First login into Markplaats!")
return 0
def load_form_page_blocking(self, url, blocking_url="", exception_url=None):
"""
Load the markplaats 'Plaats advertensie' page, busy waiting until submitted
url - page to load
blocking_url - url (beginning of url) that waits until changed differently (blocking until changed to another URL)
"""
# Open url in current tab/window
self.open_url(url)
# Switch to the document active tab (web-page)
self.switch_to_content()
# From this moment on, the write_data/read_data calls COULD be important to
# run in context of content (enter(content)), use read_data(true) when applicable and check the valid flag
# Change delivery method
self.change_delivery_method_to_send_or_pickup()
self.change_delivery_method_to_parcel_30kg()
# When no blocking url is defined use input URL instead
if blocking_url == "":
blocking_url = url
blocking_url = b'"' + blocking_url.encode('utf-8')
# Blocking wait until the current URL is different from the 'blocking url' (form submitted)
self.wait_until_url_changed(blocking_url, exception_url)
def change_delivery_method_to_send_or_pickup(self):
"""
Change the select dropbox item in Marktplaats ("Ophalen of Verzenden"), to index 3 == Ophalen of Verzenden
"""
self.write_data(b"document.getElementById('deliveryMethod').childNodes[1].childNodes[1].selectedIndex=3")
self.skip_data()
def change_delivery_method_to_parcel_letter_post(self):
"""
Delivery Method Marktplaats - Letter post (0-2Kg), max. 38 x 26,5 x 3,2cm
# Shipping data: https://api.marktplaats.nl/v1/postnl/catalog
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "350")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "1018")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "parcels")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "1000")
def change_delivery_method_to_parcel_10kg(self):
"""
Delivery Method Marktplaats - Package (0-10kg), max. 100 x 50 x 50 cm
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "650")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "3000")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "parcels")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "5000")
def change_delivery_method_to_parcel_30kg(self):
"""
Delivery Method Marktplaats - Package (10-30kg), max. 176 x 78 x 58 cm
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "1271")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "3001")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "parcels")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "20000")
def change_delivery_method_to_envelop_20g(self):
"""
Delivery Method Marktplaats - Envelop (0-20g)
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "78")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "1000")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "letters")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "10")
def change_delivery_method_to_envelop_50g(self):
"""
Delivery Method Marktplaats - Envelop (20-50g)
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "156")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "1000")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "letters")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "35")
def change_delivery_method_to_envelop_100g(self):
"""
Delivery Method Marktplaats - Envelop (50-100g)
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "234")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "1000")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "letters")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "75")
def change_delivery_method_to_envelop_250g(self):
"""
Delivery Method Marktplaats - Envelop (100-250g)
"""
self.set_hidden_input_field_form("syi-form", "shippingDetails.price", "312")
self.set_hidden_input_field_form("syi-form", "shippingDetails.provider", "postnl")
self.set_hidden_input_field_form("syi-form", "shippingDetails.productCode", "1000")
self.set_hidden_input_field_form("syi-form", "shippingDetails.catalogName", "letters")
self.set_hidden_input_field_form("syi-form", "shippingDetails.averageWeight", "175")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment