88 lines
2 KiB
Python
Executable file
88 lines
2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
from BeautifulSoup import BeautifulSoup
|
|
from selenium import webdriver
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.common.exceptions import NoSuchElementException
|
|
import urllib.request, urllib.error, urllib.parse, time, os
|
|
import setuptools
|
|
|
|
def status(driver):
|
|
if "/main/login.php" not in driver.page_source:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def loadPage(url,period=5,init=False, driver=driver):
|
|
if not (init or status(driver)):
|
|
login()
|
|
driver.get(url)
|
|
time.sleep(period)
|
|
|
|
def loginHandler(user = setuptools.user, password = setuptools.password, driver = driver):
|
|
loadPage("http://www.planetromeo.com/",10,True,driver)
|
|
|
|
curfield = driver.find_element_by_name("username")
|
|
curfield.send_keys(user)
|
|
|
|
curfield = driver.find_element_by_name("passwort")
|
|
curfield.send_keys(password)
|
|
|
|
curfield.send_keys(Keys.RETURN)
|
|
time.sleep(10)
|
|
|
|
return status()
|
|
|
|
class LoginError(Exception):
|
|
pass
|
|
|
|
def login():
|
|
if not (status() or loginHandler()):
|
|
raise LoginError("Login failed.")
|
|
return True
|
|
|
|
def messageID(url):
|
|
return url.split("?")[1]
|
|
|
|
def messageHandler(mid, driver):
|
|
loadPage("https://www.planetromeo.com/msg/?id=" + mid, driver=driver)
|
|
|
|
try:
|
|
links = driver.find_elements_by_partial_link_text('pix/popup.php/')
|
|
for link in links:
|
|
phototools.processURL(link.get_attribute('href'),vid)
|
|
except NoSuchElementException as e:
|
|
pass
|
|
|
|
def pageHandler(driver):
|
|
webpage = driver.page_source
|
|
links = BeautifulSoup(webpage).findAll('a')
|
|
count = 0
|
|
|
|
for l in links:
|
|
url = l['href']
|
|
if "/msg/?id=" in url:
|
|
count += 1
|
|
mid = messageID(url)
|
|
if mid <= dbtools.getLatestMessage()
|
|
return False
|
|
messageHandler(mid, driver)
|
|
|
|
if count == 0:
|
|
return False
|
|
|
|
return True
|
|
|
|
def siteHandler(p = 0, driver = driver):
|
|
loadPage("https://www.planetromeo.com/mitglieder/messages/uebersicht.php?seite=" + str(p), driver=driver)
|
|
if pageHandler(driver):
|
|
siteHandler(p+1, driver)
|
|
|
|
if __name__ == "__main__":
|
|
driver = webdriver.Firefox()
|
|
if login(driver):
|
|
siteHandler(driver=driver)
|
|
|
|
print("KTHXBAI")
|
|
|
|
driver.close()
|