0 Members and 1 Guest are viewing this topic.
#! /usr/bin/python#PortalView Live Desktop Wallpaper, Version 1.5#Created by GoldNugget / contact: michelle@goldnuggetwebs.com#See readme for instructionsimport cStringIOimport urllibimport Imageimport timewhile True: #file = urllib.urlopen('http://www.kaiserslautern.de/live_tools/webcam/cam2_r_640.jpg') file = urllib.urlopen('http://schulebza.selfhost.bz/GetImage.cgi?Size=1280x800') #file = urllib.urlopen('http://www.djk-landau.de/fileadmin/webcam/cam2-huge.jpg') #file = urllib.urlopen('http://www.nabu-nw.de/weinbiet/svga_links.jpg') im = cStringIO.StringIO(file.read()) img = Image.open(im) print img.format, img.size, img.mode if img.format == ('JPEG'): img.save('/home/cal/Bilder/current.jpg') elif img.format == ('PNG'): img.save('/home/cal/Bilder/current.png') elif img.format == ('GIF'): img.save('/home/cal/Bilder/current.gif') time.sleep(20)
Traceback (most recent call last): File "Downloads/live_wallpaper/getbild.py", line 53, in <module> img.save('/home/cal/Bilder/current.jpg') File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1631, in save self.load() File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 218, in load raise IOError("image file is truncated (%d bytes not processed)" % len(b))IOError: image file is truncated (28 bytes not processed)
#!/bin/bashpython /home/cal/Downloads/live_wallpaper/getpic.py & python /home/cal/Downloads/live_wallpaper/getbild.py
#! /usr/bin/python#PortalView Live Desktop Wallpaper, Version 1.5#Created by GoldNugget / contact: michelle@goldnuggetwebs.com#See readme for instructionsimport cStringIOimport urllibimport Imageimport timewhile True: #file = urllib.urlopen('http://www.kaiserslautern.de/live_tools/webcam/cam2_r_640.jpg') file = urllib.urlopen('http://schulebza.selfhost.bz/GetImage.cgi?Size=1280x800') #file = urllib.urlopen('http://www.djk-landau.de/fileadmin/webcam/cam2-huge.jpg') #file = urllib.urlopen('http://www.nabu-nw.de/weinbiet/svga_links.jpg') try: im = cStringIO.StringIO(file.read()) except IOError: pass else: img = Image.open(im) print img.format, img.size, img.mode if img.format == ('JPEG'): img.save('/home/cal/Bilder/current.jpg') elif img.format == ('PNG'): img.save('/home/cal/Bilder/current.png') elif img.format == ('GIF'): img.save('/home/cal/Bilder/current.gif') time.sleep(20)
Aber kann das sein daß phyton ein wenig, -hmm- pedantisch ist?Ich hatte die zusätzlichen Zeilen einfach abgetippt, und bekam nach dem Start zuerst eine Fehlermeldung: "IndentationError: unindent does not match any outer indentation level" Googlen sagte mir dass es wohl Probleme mit Leerzeichen oder tabs gibt, also: Leerzeichen raus.Danach hatte ich einen SyntaxError, nach Google sollten es fehlende Leerzeilen sein.... Für mich sah das im Editor alles ziemlich gleich und wie Dein Text auch aus.
cal@neskaya:~cal: pythonPython 2.7.8 (default, Aug 18 2014, 10:01:58) [GCC 4.9.1] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> helpType help() for interactive help, or help(object) for help about object.>>> help()Welcome to Python 2.7! This is the online help utility.If this is your first time using Python, you should definitely check outthe tutorial on the Internet at http://docs.python.org/2.7/tutorial/.Enter the name of any module, keyword, or topic to get help on writingPython programs and using Python modules. To quit this help utility andreturn to the interpreter, just type "quit".To get a list of available modules, keywords, or topics, type "modules","keywords", or "topics". Each module also comes with a one-line summaryof what it does; to list the modules whose summaries contain a given wordsuch as "spam", type "modules spam".help>
#! /usr/bin/python#PortalView Live Desktop Wallpaper, Version 1.5#Created by GoldNugget / contact: michelle@goldnuggetwebs.com#See readme for instructionsimport cStringIOimport urllibimport Imageimport timewhile True: try: #file = urllib.urlopen('http://www.kaiserslautern.de/live_tools/webcam/cam2_r_640.jpg') #file = urllib.urlopen('http://www.nature.nps.gov/air/webcams/parks/nacccam/washlarge.jpg') file = urllib.urlopen('http://www.opentopia.com/images/cams/world_sunlight_map_rectangular.jpg') except IOError: img = Image.open('/home/cal/screen1.jpg') #dies gibt ein Image das "Netz iss wech!" auf dem Schirm zeigt print img.format, img.size, img.mode img.save('/home/cal/Pictures/current.jpg') else: try: im = cStringIO.StringIO(file.read()) except IOError: pass else: img = Image.open(im) print img.format, img.size, img.mode if img.format == ('JPEG'): img.save('/home/cal/Pictures/current.jpg') elif img.format == ('PNG'): img.save('/home/cal/Pictures/current.png') elif img.format == ('GIF'): img.save('/home/cal/Pictures/current.gif') time.sleep(20)
import urllib2import cStringIOimport urllibimport Imageimport timeimport sysimport reimport base64from urlparse import urlparsewhile True: try: theurl = 'http://192.168.178.31/jpg/image.jpg' username = 'admin' password = '123456' # a very bad password req = urllib2.Request(theurl) base64string = base64.encodestring( '%s:%s' % (username, password))[:-1] authheader = "Basic %s" % base64string req.add_header("Authorization", authheader) try: file = urllib2.urlopen(req) im = cStringIO.StringIO(file.read()) img = Image.open(im) print img.format, img.size, img.mode img.save('/home/cal/Bilder/current.jpg') time.sleep(20) except IOError, e: # here we shouldn't fail if the username/password is right print "Ist die Kamera an?" except IOError: pass