Commit 98e18479 authored by Melroy van den Berg's avatar Melroy van den Berg

some features added

parent cb0c7113
Marktplaats Batch
=================
(almost) Automate posting advertisements by providing a CSV input file, which can save a lot of time.
\ No newline at end of file
(almost) Automate posting advertisements by providing a CSV input file, which can save a lot of time.
Reference
---------
* https://developer.mozilla.org/en/docs/Working_with_windows_in_chrome_code
* 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
......@@ -7,9 +7,12 @@ from marktplaats import Marktplaats
# Shipping trick only works in Chrome not in Firefox! Arrrg! Try setting hidden fields via javascript instead or other hacking when required.
# True, user need to press the button him/herself. False, the system automatically press the button after uploading pictures.
USER_FINAL_APPROVAL_REQUIRED=True
mp=None
try:
mp = Marktplaats()
mp = Marktplaats(USER_FINAL_APPROVAL_REQUIRED)
# Is user loggedin?
login = mp.check_marktplaats_login()
if login == 0:
......
......@@ -5,8 +5,10 @@ from mozrepl import MozRepl
from time import sleep
class Marktplaats(MozRepl):
def __init__(self):
def __init__(self, approval_req):
super(Marktplaats, self).__init__()
self.approval_req = approval_req
def check_marktplaats_login(self):
"""
Verifiy if user is already logged-in
......@@ -59,8 +61,10 @@ class Marktplaats(MozRepl):
self.open_image_picker()
while True:
# TODO: Detect if user press the OK to upload button or cancel button iso pop-up
self.close_pop_up_frontpage()
sleep(2)
print("Looping here now...")
# When no blocking url is defined use input URL instead
if blocking_url == "":
......@@ -69,7 +73,6 @@ class Marktplaats(MozRepl):
# Blocking wait until the current URL is different from the 'blocking url' (form submitted)
self.wait_until_url_changed(blocking_url, exception_url)
def open_image_picker(self):
"""
Trigger Open file picker (multiple files) in Marktplaats
......@@ -78,11 +81,28 @@ class Marktplaats(MozRepl):
self.skip_data()
def close_pop_up_frontpage(self):
self.write_data(b"document.getElementById('blikvanger-dialog').style.display")
display = self.read_data()
"""
Close spam, and directly scroll down
"""
self.write_data(b"function checkPopUp() { if(document.getElementById('blikvanger-dialog'))return document.getElementById('blikvanger-dialog').style.display;return \"none\"}; checkPopUp()")
(display,valid) = self.read_data()
if display != b'"none"':
self.write_data(b"document.getElementById('blikvanger-dialog').style.display = 'none'; document.getElementById('overlay').style.display = 'none';")
self.skip_data()
# Properly done adding pictures, just go down to the 'Plaats je advertentie' button
if self.approval_req:
self.scroll_down_page()
else:
# TODO: How do I know when a user DID NOT upload any picture at all (on purpose)???!
# Directly press the button
self.place_advertisement()
def place_advertisement(self):
"""
Trigger the place advertisement button
"""
self.write_data(b"document.getElementById('syi-place-ad-button').click()")
self.skip_data()
def change_delivery_method_to_send_or_pickup(self):
"""
......
......@@ -178,6 +178,13 @@ class MozRepl(object):
self.write_data(b"input = document.createElement('input');input.setAttribute('type', 'hidden');input.setAttribute('name', '" + name.encode('utf-8') + b"');input.setAttribute('value', '" + value.encode('utf-8') + b"');document.getElementById('" + form_id.encode('utf-8') + b"').appendChild(input);")
self.skip_data()
def scroll_down_page(self):
"""
Scroll page fully down
"""
self.write_data(b"window.scrollTo(0,document.body.scrollHeight)")
self.skip_data()
def switch_to_content(self):
self.write_data(self.SOCKET_NAME + b".enter(content)")
self.skip_data()
......
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