add setup.py
This commit is contained in:
parent
1d92e0ec65
commit
c6a7d839d9
@ -13,4 +13,5 @@ try:
|
|||||||
vsetup_logging(log_level, logfile='', stream=sys.stderr)
|
vsetup_logging(log_level, logfile='', stream=sys.stderr)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
iMain(sys.argv[1:], bgui=False)
|
if __name__ == '__main__':
|
||||||
|
iMain(sys.argv[1:], bgui=False)
|
||||||
|
11
lookupdns.py
11
lookupdns.py
@ -1,9 +1,14 @@
|
|||||||
#!/usr/local/bin/python3.sh
|
#!/usr/local/bin/python3.sh
|
||||||
# -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*
|
# -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*
|
||||||
|
|
||||||
# Looks for urls https://dns.google/resolve?
|
"""
|
||||||
# and parses them to extract a magic field.
|
Looks for urls https://dns.google/resolve?
|
||||||
# https://dns.google/resolve?name=domain.name&type=TXT&cd=true&do=true
|
https://dns.google/resolve?name=domain.name&type=TXT&cd=true&do=true
|
||||||
|
and parses them to extract a magic field.
|
||||||
|
|
||||||
|
A good example of how you can parse json embedded in HTML with phantomjs.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
79
phantompy.py
79
phantompy.py
@ -130,8 +130,6 @@ from PyQt5.QtWidgets import QApplication
|
|||||||
from PyQt5.QtPrintSupport import QPrinter
|
from PyQt5.QtPrintSupport import QPrinter
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEnginePage
|
from PyQt5.QtWebEngineWidgets import QWebEnginePage
|
||||||
|
|
||||||
from support_phantompy import vsetup_logging
|
|
||||||
|
|
||||||
global LOG
|
global LOG
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
import warnings
|
||||||
@ -164,16 +162,16 @@ def prepare(sdir='/tmp'):
|
|||||||
|
|
||||||
class Render(QWebEnginePage):
|
class Render(QWebEnginePage):
|
||||||
def __init__(self, app, do_print=False, do_save=True):
|
def __init__(self, app, do_print=False, do_save=True):
|
||||||
app.ldone = []
|
app.ldone = []
|
||||||
self._app = app
|
self._app = app
|
||||||
self.do_print = do_print
|
self.do_print = do_print
|
||||||
self.do_save = do_save
|
self.do_save = do_save
|
||||||
self.percent = 0
|
self.percent = 0
|
||||||
self.uri = None
|
self.uri = None
|
||||||
self.jsfile = None
|
self.jsfile = None
|
||||||
self.htmlfile = None
|
self.htmlfile = None
|
||||||
self.pdffile = None
|
self.pdffile = None
|
||||||
QWebEnginePage.__init__(self)
|
QWebEnginePage.__init__(self)
|
||||||
|
|
||||||
def run(self, url, pdffile, htmlfile, jsfile):
|
def run(self, url, pdffile, htmlfile, jsfile):
|
||||||
self._app.lstart.append(id(self))
|
self._app.lstart.append(id(self))
|
||||||
@ -205,36 +203,37 @@ class Render(QWebEnginePage):
|
|||||||
LOG.debug(f"phantom.py: loading 10")
|
LOG.debug(f"phantom.py: loading 10")
|
||||||
|
|
||||||
def _onConsoleMessage(self, *args):
|
def _onConsoleMessage(self, *args):
|
||||||
if len(args) > 3:
|
if len(args) > 3:
|
||||||
level, txt, lineno, filename = args
|
level, txt, lineno, filename = args
|
||||||
else:
|
else:
|
||||||
level = 1
|
level = 1
|
||||||
txt, lineno, filename = args
|
txt, lineno, filename = args
|
||||||
LOG.debug(f"CONSOLE {lineno} {txt} {filename}")
|
LOG.debug(f"CONSOLE {lineno} {txt} {filename}")
|
||||||
if "__PHANTOM_PY_DONE__" in txt:
|
if "__PHANTOM_PY_DONE__" in txt:
|
||||||
self.percent = 40
|
self.percent = 40
|
||||||
# If we get this magic string, it means that the external JS is done
|
# If we get this magic string, it means that the external JS is done
|
||||||
if self.do_save:
|
if self.do_save:
|
||||||
self.toHtml(self._html_callback)
|
self.toHtml(self._html_callback)
|
||||||
return
|
return
|
||||||
# drop through
|
# drop through
|
||||||
txt = "__PHANTOM_PY_SAVED__"
|
txt = "__PHANTOM_PY_SAVED__"
|
||||||
if "__PHANTOM_PY_SAVED__" in txt:
|
if "__PHANTOM_PY_SAVED__" in txt:
|
||||||
self.percent = 50
|
self.percent = 50
|
||||||
if self.do_print:
|
if self.do_print:
|
||||||
self._print()
|
self._print()
|
||||||
return
|
return
|
||||||
txt = "__PHANTOM_PY_PRINTED__"
|
txt = "__PHANTOM_PY_PRINTED__"
|
||||||
if "__PHANTOM_PY_PRINTED__" in txt:
|
if "__PHANTOM_PY_PRINTED__" in txt:
|
||||||
self.percent = 60
|
self.percent = 60
|
||||||
self._exit(level)
|
self._exit(level)
|
||||||
|
|
||||||
def _loadFinished(self, result):
|
def _loadFinished(self, result):
|
||||||
self.percent = 30
|
# RenderProcessTerminationStatus ?
|
||||||
LOG.info(f"phantom.py: _loadFinished {result} {self.percent}")
|
self.percent = 30
|
||||||
LOG.debug(f"phantom.py: Evaluating JS from {self.jsfile}")
|
LOG.info(f"phantom.py: _loadFinished {result} {self.percent}")
|
||||||
self.runJavaScript("document.documentElement.contentEditable=true")
|
LOG.debug(f"phantom.py: Evaluating JS from {self.jsfile}")
|
||||||
self.runJavaScript(self.js_contents)
|
self.runJavaScript("document.documentElement.contentEditable=true")
|
||||||
|
self.runJavaScript(self.js_contents)
|
||||||
|
|
||||||
def _html_callback(self, *args):
|
def _html_callback(self, *args):
|
||||||
"""print(self, QPrinter, Callable[[bool], None])"""
|
"""print(self, QPrinter, Callable[[bool], None])"""
|
||||||
|
@ -13,6 +13,7 @@ from PyQt5.QtWidgets import (QProgressBar, QWidget, QVBoxLayout)
|
|||||||
|
|
||||||
from phantompy import Render
|
from phantompy import Render
|
||||||
# from lookupdns import LookFor as Render
|
# from lookupdns import LookFor as Render
|
||||||
|
from support_phantompy import vsetup_logging, omain_argparser
|
||||||
|
|
||||||
global LOG
|
global LOG
|
||||||
import logging
|
import logging
|
||||||
@ -63,23 +64,20 @@ async def main(widget, app, ilen):
|
|||||||
app.exit()
|
app.exit()
|
||||||
# raise asyncio.CancelledError
|
# raise asyncio.CancelledError
|
||||||
return
|
return
|
||||||
LOG.debug(f"{app.ldone} {perc} {seconds}")
|
LOG.debug(f"{app.ldone} {seconds}")
|
||||||
except asyncio.CancelledError as ex:
|
except asyncio.CancelledError as ex:
|
||||||
LOG.debug("Task cancelled")
|
LOG.debug("Task cancelled")
|
||||||
|
|
||||||
def iMain(largs):
|
def iMain(largs):
|
||||||
parser = oMainArgparser()
|
parser = omain_argparser()
|
||||||
oargs = parser.parse_args(lArgs)
|
oargs = parser.parse_args(largs)
|
||||||
bgui=oargs.show_gui
|
bgui=oargs.show_gui
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from support_phantompy import vsetup_logging
|
|
||||||
d = int(os.environ.get('DEBUG', 0))
|
d = int(os.environ.get('DEBUG', 0))
|
||||||
if d > 0:
|
if d > 0:
|
||||||
vsetup_logging(10, stream=sys.stderr)
|
oargs.log_level = 10
|
||||||
else:
|
vsetup_logging(oargs.log_level, logfile='', stream=sys.stderr)
|
||||||
vsetup_logging(oargs.log_level, stream=sys.stderr)
|
|
||||||
vsetup_logging(log_level, logfile='', stream=sys.stderr)
|
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
|
@ -80,7 +80,7 @@ def vsetup_logging(log_level, logfile='', stream=sys.stdout):
|
|||||||
'NOTSET': logging.NOTSET,
|
'NOTSET': logging.NOTSET,
|
||||||
}
|
}
|
||||||
|
|
||||||
def omain__argparser(_=None):
|
def omain_argparser(_=None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from OpenSSL import SSL
|
from OpenSSL import SSL
|
||||||
@ -106,9 +106,9 @@ def omain__argparser(_=None):
|
|||||||
help="Operate on the HTML file with javascript")
|
help="Operate on the HTML file with javascript")
|
||||||
parser.add_argument('--html_output', type=str, default='',
|
parser.add_argument('--html_output', type=str, default='',
|
||||||
help="Write loaded and javascripted result to a HTML file")
|
help="Write loaded and javascripted result to a HTML file")
|
||||||
parser.add_argument('--pdf_output', type=str, default=''),
|
parser.add_argument('--pdf_output', type=str, default='',
|
||||||
help="Write loaded and javascripted result to a PDF file")
|
help="Write loaded and javascripted result to a PDF file")
|
||||||
parser.add_argument('--show_gui', type=bool, store_action=True),
|
parser.add_argument('--show_gui', type=bool, default=False, store_action=True),
|
||||||
help="show a progress meter that doesn't work")
|
help="show a progress meter that doesn't work")
|
||||||
parser.add_argument('html_url', type=str, nargs='?',
|
parser.add_argument('html_url', type=str, nargs='?',
|
||||||
required=True,
|
required=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user