LINUX.ORG.RU

[python, поделие] помогите со скриптом


0

0

Есть следующий код

main.py

#!/usr/bin/env python
import os
import subprocess

const_url = "http://172.19.30.121:8080/ui/mobile/jsp/"
dest_path = "/home/vv/media/screens/"

try:
	sourceFile1 = open("data/res", "rb")
except:
	print "Cannot find file with resolutions!\nExit..."
	exit(1)

try:
	sourceFile2 = open("data/uas", "rb")
except:
	print "Cannot find file with user agents!\nExit..."
	exit(1)

try:
	sourceFile3 = open("data/pages", "rb")
except:
	print "Cannot find file with pages!\nExit..."
	exit(1)

page = ""
userAgent = ""
filename = ""
url = ""

while 1:
	url = sourceFile3.readline()

	if not url:
		break

	while 1:
		userAgent = sourceFile2.readline()

		if not userAgent:
			break

		while 1:
			resolution_str = sourceFile1.readline()[:-1]

			if not resolution_str:
				break

			page = const_url + url[:-1]
			filename = dest_path + userAgent + "_" + resolution_str + "_" + url[:-1] + ".png"
			arguments = ["python", "screen.py", userAgent, resolution_str, page, filename]
			subprocess.call(arguments);

screen.py

#!/usr/bin/env python
import sys
import signal

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage

class WebPage(QWebPage):
	def __init__(self, user_agent, confirm=True):
		QWebPage.__init__(self)
		self.user_agent = user_agent
		self.confirm = confirm

	def userAgentForUrl(self, url):
		return self.user_agent


def onLoadFinished(result):
	if not result:
		print "Request failed"
		sys.exit(1)

	# Paint this frame into an image
	image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
	painter = QPainter(image)
	webpage.mainFrame().render(painter)
	painter.end()
	# filename
	image.save(qtargs[4])
	sys.exit(0)

qtargs = sys.argv[:]
qtargs.append("-display")
qtargs.append(":0")

app = QApplication(qtargs,True)
signal.signal(signal.SIGINT, signal.SIG_DFL)

# userAgent
webpage = WebPage(qtargs[1])

# resolution
dims = qtargs[2].split("x")
viewportSize = QSize(int(dims[0]), int(dims[1]))
webpage.setViewportSize(viewportSize)

# page
webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
webpage.mainFrame().load(QUrl(qtargs[3]))

sys.exit(app.exec_())

если запускать main.py то получаю «Request failed», но если запускать screen.py с параметрами - то все ОК.

Подскажите какую доку посмотреть или где моя ошибка..

★★★★★

мой завтык. все ОК :)

ZuBB ★★★★★ ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.