Commit f0d2ec37 authored by Melroy van den Berg's avatar Melroy van den Berg

improved version

parent c537c7e5
......@@ -8,7 +8,5 @@ Reference
* https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMChromeWindow
* https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils
* https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker
* http://ecg-marktplaats.github.io/marktplaats-api/authentication.html
* view-source:https://s.marktplaats.com/aurora/res/javascript/dist/ee1c54f1/pages/Syi.js
* https://www.marktplaats.nl/i/help/verkopen-via-marktplaats/advertentietarieven.dot.html#mpzak
......@@ -3,6 +3,8 @@
# By: Melroy van den Berg
from marktplaats import Marktplaats
from text_color import TextColor
from category import MP_Category
__version__= 1.0
# https://www.marktplaats.nl/syi/201/228/plaatsAdvertentie.html?bucket=38&complete=true&origin=HEADER&l1=201&l2=228&title=Test&attribute[condition]=31&attribute[level]=1950&attribute[orientation]=1955&price.bidding=free-bidding&description=blah&price.value=25,50&acceptPaypal=true&attribute[delivery]=35&shippingDetails.price=650&shippingDetails.provider=postnl&shippingDetails.productCode=3000&shippingDetails.catalogName=parcels&shippingDetails.averageWeight=5000
......@@ -29,7 +31,14 @@ try:
mp.load_page_blocking("https://www.marktplaats.nl/account/login.html?target=https%3A%2F%2Fwww.marktplaats.nl%2F", "https://www.marktplaats.nl/account/login.html", "https://www.marktplaats.nl/cookiewall")
print (TextColor.OKGREEN + "INFO: Succesful login (hopefully), continue..." + TextColor.ENDC)
mp.load_form_page_blocking("https://www.marktplaats.nl/syi/201/228/plaatsAdvertentie.html?bucket=38&complete=true&origin=HEADER&l1=201&l2=228&title=Test&attribute[condition]=31&attribute[level]=1950&attribute[orientation]=1955&price.bidding=free-bidding&description=blah&price.value=25,50&acceptPaypal=true&contactInformation.sellerName=Melroy&contactInformation.phoneNumber=0628814764&contactInformation.postCode=6605DW")
data = {
'title': "Example",
'category': MP_Category.BOEKEN_AUTOS_BOEKEN,
'delivery_method': "parcel_30kg",
'description': "blablabla"
}
mp.load_marktplaats_form(data)
except (KeyboardInterrupt, SystemExit):
print (TextColor.OKGREEN + "Exit, bye bye.")
if mp:
......
......@@ -37,17 +37,17 @@ class Marktplaats(MozRepl):
print (TextColor.OKGREEN + "INFO: First login into Markplaats!" + TextColor.ENDC)
return 0
def load_form_page_blocking(self, url, blocking_url="", exception_url=None):
def load_marktplaats_form(self, data):
"""
Load the markplaats 'Plaats advertensie' page, do some magic tricks here
Input(s): url - page to load
blocking_url - url (beginning of url) that waits until changed differently (blocking until changed to another URL)
"""
# When no blocking url is defined use input URL instead
if blocking_url == "":
blocking_url = url
blocking_url = b'"' + blocking_url.encode('utf-8')
# Keep bucket empty, not interested
url = "https://www.marktplaats.nl/syi/" + data['category'].value + "/plaatsAdvertentie.html?bucket=&complete=true&origin=HEADER&title=Test&attribute[condition]=31&attribute[level]=1950&attribute[orientation]=1955&price.bidding=free-bidding&description=blah&price.value=25,50&acceptPaypal=true&contactInformation.sellerName=Melroy&contactInformation.phoneNumber=0628814764&contactInformation.postCode=6605DW"
blocking_url = b'"' + url.encode('utf-8')
# Open url in current tab/window
self.open_url(url)
......@@ -57,6 +57,9 @@ class Marktplaats(MozRepl):
# 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
# TODO: Read Excel sheet to determ this question, so pop-ups would be required only if undefined
image_required = self.ask_image_upload(data['title'])
# Wait a bit longer to load the page fully
sleep(0.2)
......@@ -64,52 +67,49 @@ class Marktplaats(MozRepl):
self.change_delivery_method_to_send_or_pickup()
self.change_delivery_method_to_parcel_30kg()
data = {
'title': "Example",
'delivery_method': "parcel_30kg",
'description': "blablabla"
}
# TODO: Read Excel sheet to determ this question, so pop-ups would be required only if undefined
image_required = self.ask_image_upload(data['title'])
if image_required:
# Image required, lets help the user
print(TextColor.OKBLUE + "NOTE: Please, be-sure you accept pop-ups of 'marktplaats.nl'. Press allow." + TextColor.ENDC)
self.open_image_picker()
# Busy wait
is_focus_action_triggered=False
while True:
# I could also look at the change event of the hidden image id fields
image_uploaded=self.close_pop_up_frontpage()
# Busy wait until images are uploaded
trigger_action_done=False
while True:
# TODO: I could also look at the change event of the hidden image id fields, if that is better?
image_uploaded=self.close_pop_up_frontpage()
if image_required:
# Wait until the images are uploaded (the pop-up window is the trigger)
if image_uploaded:
if not is_focus_action_triggered:
is_focus_action_triggered=True
if self.approval_req:
# Only scroll-down to the bottom of the page. User interaction still needed.
self.scroll_down_page()
else:
# Just wait a bit longer in order to process the images
sleep(2.5)
# Place the ad!
self.place_advertisement()
# Check if URL is changed
(changed, valid) = self.is_url_changed(blocking_url, exception_url)
if changed:
# URL changed! Next!
break
if valid:
# Otherwise, sleep a bit, when data was valid
sleep(1)
sleep(0.5)
else:
sleep(0.2)
if self.approval_req:
# Only scroll-down to the bottom of the page. User interaction still needed.
self.scroll_down_page()
if not trigger_action_done:
trigger_action_done=True
# sleep a bit
self.trigger_submit_scrolldown(sleep_needed=True)
else:
# Place the ad!
self.place_advertisement()
# No image required, continue
if not trigger_action_done:
trigger_action_done=True
self.trigger_submit_scrolldown()
# Check if URL is changed
(changed, valid) = self.is_url_changed(blocking_url)
if changed:
# URL changed! Next!
break
if valid:
# Otherwise, sleep a bit, when data was valid
sleep(1)
sleep(0.5)
def trigger_submit_scrolldown(self, sleep_needed=False):
if self.approval_req:
# Only scroll-down to the bottom of the page. User interaction still needed.
self.scroll_down_page()
else:
if sleep_needed:
sleep(2.5)
# Place the ad!
self.place_advertisement()
def ask_image_upload(self, title):
......@@ -118,7 +118,7 @@ class Marktplaats(MozRepl):
return true if he/she wants to upload an image. False if not.
"""
needed=True
self.write_data(b"function isUploadNeeded() { return confirm(\"Wilt u foto(s) uploaden voor '" + title.encode('utf-8') + b"'?\") } isUploadNeeded()")
self.write_data(b"function isUploadNeeded() { return confirm(\"Wilt u foto(s) uploaden voor '" + title.encode('utf-8') + b"'? Annuleren betekent nee.\") } isUploadNeeded()")
(needed,valid) = self.read_data()
if needed == b"false":
needed=False
......
......@@ -87,7 +87,7 @@ class MozRepl(object):
exit(1)
def wait_until_url_changed(self, blocking_url, exception_url):
def wait_until_url_changed(self, blocking_url, exception_url=None):
"""
Busy wait around is_url_changed(). Only breaks when URL is changed.
"""
......@@ -102,7 +102,7 @@ class MozRepl(object):
sleep(3)
def is_url_changed(self, blocking_url, exception_url):
def is_url_changed(self, blocking_url, exception_url=None):
"""
Check if the current URL is changed, and is different from the blocking url.
......
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