Skript Fehlermeldung
Verfasst: Montag 7. Februar 2011, 18:44
Hallo!
Folgendes:
Ich habe ein Skript aus dem Internet aufgegabelt und möchte es verwenden. Ich bin allerdings nicht im Umgang mit Python vertraut und bekomme lediglich eine Fehlermeldung. Eventuell könnt ihr mir weiterhelfen?
Das ist das Skript:
Dieses habe ich in eine DATEI.py gepackt und Python mittels Python 2.7.1 Windows Installer installiert. Nun meine Frage: Die Datei muss doch in der Shell ausgeführt werden, nicht? Wenn ich die Datei ausführe bekomme ich die Fehlermeldung "expected an indeted block". Muss ich jetzt alle entsprechenden Zeilen einrücken? Was mache ich falsch?
Sorry, bin wie gesagt nicht mit Python vertraut und möchte nur dieses eine Skript zum Laufen bringen.
Danke im Voraus!
Folgendes:
Ich habe ein Skript aus dem Internet aufgegabelt und möchte es verwenden. Ich bin allerdings nicht im Umgang mit Python vertraut und bekomme lediglich eine Fehlermeldung. Eventuell könnt ihr mir weiterhelfen?
Das ist das Skript:
Code: Alles auswählen
from curl import *
import Image, ImageFile, StringIO
curl = 0
mapX = 0
mapY = 0
tileWidth = 336
tileHeight = 248
def prepare():
global curl, mapX, mapY
curl = pycurl.Curl()
# Pretend to be a popular browser. And don’t forget to set up a file to store the cookies, which
# are needed here!
curl.setopt(pycurl.USERAGENT, ‘Mozilla/4.0 (compatible; MSIE 6.0)’)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.COOKIEJAR, ’stadtplan_cookies.txt’)
curl.setopt(pycurl.URL, ‘http://www.fahrinfo-berlin.de/Stadtplan/index’)
curl.setopt(pycurl.HTTPGET, 1)
# Send this initial request and ignore the resulting HTML page. This will create a new session
# on the server.
dev_null = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, dev_null.write)
curl.perform()
dev_null.close()
# This is the position on the map at which the BVG application starts
mapX = 26
mapY = 34
def download(x, y):
# If the connection to the server has not yet been established, do it now.
global curl, mapX, mapY
if curl == 0:
prepare()
# Move the map to the desired location by sending fake scroll clicks to the server.
dev_null = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, dev_null.write)
print ‘Seeking to ‘ + str(x) + ‘, ‘ + str(y) + ‘… ‘,
while (mapX != x) or (mapY != y):
direction = ”
if y < mapY:
direction = direction + ‘N’
mapY = mapY – 1
elif y > mapY:
direction = direction + ‘S’
mapY = mapY + 1
if x < mapX:
direction = direction + ‘W’
mapX = mapX – 1
elif x > mapX:
direction = direction + ‘E’
mapX = mapX + 1
curl.setopt(pycurl.URL, ‘http://www.fahrinfo-berlin.de/Stadtplan/index?move=’ + direction + ‘&’)
curl.perform()
dev_null.close()
# Now that the map is at the correct location, download the map image.
print ‘Downloading map image… ‘,
curl.setopt(pycurl.URL, ‘http://www.fahrinfo-berlin.de/Stadtplan/index/image?ref=0′)
imageParser = ImageFile.Parser()
curl.setopt(pycurl.WRITEFUNCTION, imageParser.feed)
curl.perform()
# As the map images contain a scale in the bottom left corner, we’ll just use the top left quarter of it.
print ‘Decoding and cropping image’
mapImage = imageParser.close()
mapTile = mapImage.crop((0, 0, tileWidth, tileHeight))
return mapTile
# Define which part of the map we want to download and create a huge image in which the individual tiles will
# be composited.
box = (0, 0, 60, 67)
completeMap = Image.new(‘RGB’, (tileWidth * (box[2] – box[0]), tileHeight * (box[3] – box[1])))
# Download each tiny map image and composite it onto the huge map image.
for y in range(box[1], box[3]):
for x in range(box[0], box[2]):
tile = download(x, y)
completeMap.paste(tile, ((x – box[0]) * tileWidth, (y – box[1]) * tileHeight))
# Save the whole map after each row. Better to be save than sorry!
completeMap.save(‘plan.png’)
# Close the connection to the server. We’re done here!
curl.close()Sorry, bin wie gesagt nicht mit Python vertraut und möchte nur dieses eine Skript zum Laufen bringen.
Danke im Voraus!