Forked romeotools for ScriptzBaseTools

This commit is contained in:
Klaus-Uwe Mitterer 2017-09-09 14:40:28 +02:00
parent ff759fbf7b
commit aa2795f46d
4 changed files with 35 additions and 139 deletions

View file

@ -4,11 +4,11 @@ from bs4 import BeautifulSoup
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
import multiprocessing, urllib.request, urllib.error, urllib.parse, time, os import glob, multiprocessing, re, requests, urllib.request, urllib.error, urllib.parse, time, os
import dbtools, phototools, setuptools import setuptools
def status(driver): def status(driver):
if "Unauthorised Access" not in driver.page_source and "/main/login.php" not in driver.page_source and len(driver.page_source) > 100: if "Benutzername oder E-Mail-Adresse:" not in driver.page_source and 'href="login/"' not in driver.page_source:
return True return True
else: else:
return False return False
@ -20,13 +20,12 @@ def loadPage(url, driver, period=5,init=False):
time.sleep(period) time.sleep(period)
def loginHandler(driver, user = setuptools.user(), password = setuptools.password()): def loginHandler(driver, user = setuptools.user(), password = setuptools.password()):
loadPage("https://classic.planetromeo.com/",driver,3,True) loadPage("https://scriptzbase.org/login/",driver,3,True)
loadPage("https://classic.planetromeo.com/main/login.php",driver,3,True)
curfield = driver.find_element_by_name("username") curfield = driver.find_element_by_name("login")
curfield.send_keys(user) curfield.send_keys(user)
curfield = driver.find_element_by_name("passwort") curfield = driver.find_element_by_name("password")
curfield.send_keys(password) curfield.send_keys(password)
curfield.send_keys(Keys.RETURN) curfield.send_keys(Keys.RETURN)
@ -42,99 +41,39 @@ def login(driver):
raise LoginError("Login failed.") raise LoginError("Login failed.")
return True return True
def messageID(url): def pageHandler(driver):
return url.split("=")[-1]
def quickshareHandler(driver, url, sender):
nurl = "https://classic.planetromeo.com/" + url if "planetromeo.com" not in url else url
loadPage(nurl)
juha = BeautifulSoup(driver.page_source, "html5lib") juha = BeautifulSoup(driver.page_source, "html5lib")
try: session = requests.Session()
links = juha.findAll("a") kekse = driver.get_cookies()
for link in links:
try:
purl = "https://classic.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()): for keks in kekse:
if mode == 0: session.cookies.set(cookie["name"], cookie["value"])
loadPage("https://classic.planetromeo.com/msg/?id=" + mid, driver)
else:
loadPage("https://classic.planetromeo.com/msg/?type=sent&id=" + mid, driver)
juha = BeautifulSoup(driver.page_source, "html5lib")
text = juha.select("div.msg div")[0]
db.executeQuery("INSERT INTO messages(id, text, sender_id, recipient_id, created_at) VALUES('%s', '%s', '%s', '%s', '%s');" % (mid, setuptools.unescapeText(text.text).strip(), sender, recipient, date)) for a in juha.findAll("a"):
db.commit() if "/download?version=" in a["href"]:
fid = a["href"].split("=")[1]
if not glob.glob("files/sbd%s*" % fid):
res = session.get(a["href"])
fname = re.findall("filename=(.+)", res.headers["content-disposition"])
try: with open("files/sbd%s_%s" % (fid, fname), "wb") as out:
links = juha.findAll("a") out.write(res.content)
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
def pageHandler(driver, db = dbtools.dbHelper()): def siteHandler(driver, p = 1):
mode = 0 loadPage("https://scriptzbase.org/nulled_scripts/categories/scripts-templates.145/?page=" + str(p), driver)
abort = True
juha = BeautifulSoup(driver.page_source, "html5lib")
if "sent" in driver.current_url: if driver.current_url[-len(str(p)):] == str(p):
mode = 1 if pageHandler(driver):
siteHandler(driver, p+1)
try: def mainHandler(driver):
for msg in juha.select("table.messageCenter tr")[1:]:
try:
data = msg.findAll('td')
user = data[1].string
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)
else:
messageHandler(setuptools.user(), user, mid, date, driver, mode, db)
except IndexError:
pass
except IndexError:
return False
if abort:
return False
else:
return True
def siteHandler(driver, mode = 0, p = 0, db = dbtools.dbHelper()):
if mode == 0:
loadPage("https://classic.planetromeo.com/mitglieder/messages/uebersicht.php?view=all&seite=" + str(p), driver)
else:
loadPage("https://classic.planetromeo.com/mitglieder/messages/uebersicht.php?view=sent&seite=" + str(p), driver)
if pageHandler(driver, db):
siteHandler(driver, mode, p+1, db)
def mainHandler(driver, db):
loginHandler(driver) loginHandler(driver)
siteHandler(driver, 0, db=db) siteHandler(driver)
siteHandler(driver, 1, db=db)
if __name__ == "__main__": if __name__ == "__main__":
db = dbtools.dbHelper()
caps = webdriver.DesiredCapabilities().PHANTOMJS.copy() caps = webdriver.DesiredCapabilities().PHANTOMJS.copy()
caps["phantoms.page.settings.userAgent"] = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0" caps["phantoms.page.settings.userAgent"] = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"
driver = webdriver.PhantomJS(desired_capabilities=caps) driver = webdriver.PhantomJS(desired_capabilities=caps)
mainHandler(driver, db) mainHandler(driver)
driver.close() driver.close()

View file

@ -1,43 +0,0 @@
import argparse, os, requests, sys
def log(string, shutup = False, output = sys.stderr):
if not shutup:
print(string, file=output)
def verboselog(string, verbose = False, output = sys.stderr):
if verbose:
log(string, False, output)
def fileDownloader(url, sender = False, directory = False):
os.makedirs("%s/%s" % (directory or ".", sender or "."), exist_ok=True)
filename = "%s/%s/%s" % (directory or ".", sender or ".", url.split('/')[-1])
remote = requests.get(url, stream=True)
with open(filename, 'wb') as outfile:
for chunk in remote.iter_content(chunk_size=1024):
if chunk:
outfile.write(chunk)
outfile.flush()
def urlparse(url):
if "/img/usr/" in url:
return url
if "/auswertung/pix/popup.php/" in url:
return "http://www.planetromeo.com/img/usr/%s" % url.split("/")[-1].split("?")[0]
else:
raise ValueError("%s is not a valid URL" % url)
def processURL(url, sender = False, directory = "photos", geturls = False, verbose = False, shutup = False):
verboselog("Processing URL %s..." % url, verbose)
try:
purl = urlparse(url)
except ValueError as e:
log("Notice: %s. Skipping." % e, shutup)
else:
if purl == url:
log("Warning: You may have copied the image URL rather than the link URL from the message window. Use the link URL instead!", shutup)
if geturls:
print(purl)
else:
verboselog("Downloading file to directory %s..." % sender, verbose)
fileDownloader(purl, sender, directory)

View file

@ -10,7 +10,7 @@ config = configparser.RawConfigParser()
config.add_section('Database') config.add_section('Database')
print('''Romeotools will use a database for certain tasks. You can use a file or a MySQL database for this purpose. print('''SBTools will use a database for certain tasks. You can use a file or a MySQL database for this purpose.
If you wish to use a MySQL database, you will need the credentials for it. If you don't know what any of that means, stick with the default value and just press Enter. If you wish to use a MySQL database, you will need the credentials for it. If you don't know what any of that means, stick with the default value and just press Enter.
''') ''')
@ -55,11 +55,11 @@ if not db.isInitialized():
db.closeConnection() db.closeConnection()
config.add_section("Romeo") config.add_section("SB")
print('''In the next step, we'll get you connected to PlanetRomeo. For this, we print('''In the next step, we'll get you connected to ScriptzBase. For this, we
will need your username and password. Please note that these will be stored on will need your username and password. Please note that these will be stored on
your hard disk in plain text. Sadly PlanetRomeo doesn't offer a better way for your hard disk in plain text. Sadly ScriptzBase doesn't offer a better way for
third party applications to authenticate... third party applications to authenticate...
''') ''')
@ -67,8 +67,8 @@ unam = input("Username: ")
pwrd = getpass.getpass("Password (not echoed back!): ") pwrd = getpass.getpass("Password (not echoed back!): ")
print() print()
config.set("Romeo", "user", unam) config.set("SB", "user", unam)
config.set("Romeo", "pass", pwrd) config.set("SB", "pass", pwrd)
print("Seems like everything worked out fine. Let's write that config file...") print("Seems like everything worked out fine. Let's write that config file...")

View file

@ -51,13 +51,13 @@ def dbpath():
def user(): def user():
try: try:
return getSetting("Romeo", "user") return getSetting("SB", "user")
except: except:
raise SetupException() raise SetupException()
def password(): def password():
try: try:
return getSetting("Romeo", "pass") return getSetting("SB", "pass")
except: except:
raise SetupException() raise SetupException()