ich habe eine Datei 'bilder', welche den zukünftigen Bildnamen und eine dazugehörige URL getrennt von einem Trennzeichen (#!) enthält:
Mein Programm soll das Bild, welches die URL angibt herunter laden und das Bild mit dem Namen (vor dem #!) umbenennen. Hier mein Versuch:tweetabit#!http://static.twitter.com/images/defaul ... normal.png
lia06#!http://s3.amazonaws.com/twitter_product ... normal.jpg
vogti#!http://s3.amazonaws.com/twitter_product ... normal.gif
tweetabit#!http://static.twitter.com/images/defaul ... normal.png
tweetabit#!http://static.twitter.com/images/defaul ... normal.png
lia06#!http://s3.amazonaws.com/twitter_product ... normal.jpg
lia06#!http://s3.amazonaws.com/twitter_product ... normal.jpg
vogti#!http://s3.amazonaws.com/twitter_product ... normal.gif
lia06#!http://s3.amazonaws.com/twitter_product ... normal.jpg
[
Code: Alles auswählen
# -*- coding: cp1252 -*-
import pycurl
def speicher_bild(name,url):
f = open('pics1/%s.jpg' % (name), 'w') # Öffnen einer Datei name.jpg
c = pycurl.Curl() # Optionen für cURL
c.setopt(pycurl.URL, url) # Angabe der URL
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.POST, 0)
c.setopt(c.NOPROGRESS, 0)
c.setopt(c.FOLLOWLOCATION, 1)
c.setopt(c.MAXREDIRS, 5)
c.setopt(c.WRITEDATA, f) # Nach dem Herunterladen in die Datei name.jpg schreiben
c.perform()
c.close()
f.seek(0)
f.close()
def name_bild():
name=''
url=''
datei = open('bilder', 'r')
weiter = True
while weiter:
line = datei.readline()
if len(line) == 0:
weiter = False
break
else:
a=line.find('#!')
for i in range (0,a): # Namen auslesen
name=name+line[i]
print name
b=line.find('\n')
for l in range (a+2,b): # URL auslesen
url=url+line[l]
print url
speicher_bild(name,url) # Namen und URL an speicher_bild() übergeben
name=''
url=''
execute=name_bild()
Jemand eine Idee, was ich falsch mache? Glaube, dass bei speicher_bild() etwas nicht stimmt. Namen und URL gibt er ja richtig aus!