Commit ce1fec74 authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Handle photos, correct counter

parent c53ffa66
......@@ -7,10 +7,6 @@ from selenium.common.exceptions import NoSuchElementException
import multiprocessing, urllib.request, urllib.error, urllib.parse, time, os
import dbtools, phototools, setuptools
currentRun = []
rec = 0
snt = 0
def status(driver):
if "/main/login.php" not in driver.page_source:
return True
......@@ -49,8 +45,23 @@ def login(driver):
def messageID(url):
return url.split("=")[-1]
def quickshareHandler(driver, url, sender):
nurl = "https://www.planetromeo.com/" + url if "planetromeo.com" not in url else url
loadPage(nurl)
juha = BeautifulSoup(driver.page_source, "html5lib")
try:
links = juha.findAll("a")
for link in links:
try:
purl = "https://www.planetromeo.com/" + link["data-pic"] if "planetromeo.com" not in link["data-pic"] else link["data-pic"]
phototools.processURL(purl, sender, shutup=True)
except:
pass
except:
pass
def messageHandler(sender, recipient, mid, date, driver, mode = 0, db = dbtools.dbHelper()):
global currentRun
if mode == 0:
loadPage("https://www.planetromeo.com/msg/?id=" + mid, driver)
else:
......@@ -66,17 +77,20 @@ def messageHandler(sender, recipient, mid, date, driver, mode = 0, db = dbtools.
for link in links:
if "/pix/popup.php/" in link["href"]:
phototools.processURL(link["href"], sender)
try:
db.executeQuery("INSERT INTO photos(mid, pid) VALUES('%s', '%s');" % (mid, phototools.parseurl(link["href"]).split('/')[-1]))
except:
pass
if "/quickshare/" in link["href"]:
quickshareHandler(driver, link["href"], sender)
except:
pass
currentRun += [mid]
def pageHandler(driver, db = dbtools.dbHelper()):
global currentRun, rec, snt
count = 0
def pageHandler(driver, db = dbtools.dbHelper(), ret = {"rec": 0,"snt": 0}):
mode = 0
abort = True
juha = BeautifulSoup(driver.page_source, "html5lib")
mode = 0
if "sent" in driver.current_url:
mode = 1
......@@ -88,45 +102,47 @@ def pageHandler(driver, db = dbtools.dbHelper()):
mid = messageID(data[2].find("a")["href"])
date = data[3].string
if not db.checkID(mid):
abort = False
if mode == 0:
messageHandler(user, setuptools.user(), mid, date, driver, mode, db)
rec += 1
ret["rec"] += 1
else:
messageHandler(setuptools.user(), user, mid, date, driver, mode, db)
snt += 1
count += 1
ret["snt"] += 1
except IndexError:
pass
except IndexError:
return False
if count == 0:
if abort:
return False
else:
return True
return True
def siteHandler(driver, mode = 0, p = 0, db = dbtools.dbHelper()):
def siteHandler(driver, mode = 0, ret = {"rec": 0,"snt": 0}, p = 0, db = dbtools.dbHelper()):
if mode == 0:
loadPage("https://www.planetromeo.com/mitglieder/messages/uebersicht.php?view=all&seite=" + str(p), driver)
else:
loadPage("https://www.planetromeo.com/mitglieder/messages/uebersicht.php?view=sent&seite=" + str(p), driver)
if pageHandler(driver, db):
siteHandler(driver, mode, p+1, db)
def mainHandler():
siteHandler(driver, db=db)
siteHandler(driver, 1, db=db)
if pageHandler(driver, db, ret):
siteHandler(driver, mode, ret, p+1, db)
def mainHandler(ret = {"rec": 0,"snt": 0}):
siteHandler(driver, 0, ret, db=db)
siteHandler(driver, 1, ret, db=db)
if __name__ == "__main__":
db = dbtools.dbHelper()
driver = webdriver.Firefox()
ret = {"rec": 0,"snt": 0}
if loginHandler(driver):
p = multiprocessing.Process(target=mainHandler)
p = multiprocessing.Process(target=mainHandler, args=([ret]))
p.start()
p.join(1500)
if p.is_alive():
p.terminate()
p.join()
driver.close()
print("Received", rec, "messages")
print("Sent", snt, "messages")
print("Received", ret["rec"], "messages")
print("Sent", ret["snt"], "messages")
......@@ -50,6 +50,7 @@ else:
db = dbtools.dbObject(dbtype=dbtype, path=dbpath)
if not db.isInitialized():
db.executeQuery("CREATE TABLE messages(`id` INTEGER NOT NULL, `text` TEXT, `sender_id` VARCHAR(60), `recipient_id` VARCHAR(60), `created_at` TEXT, PRIMARY KEY(id));")
db.executeQuery("CREATE TABLE photos(`mid` TEXT, `pid` TEXT);")
db.commit()
db.closeConnection()
......
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