Advertisement
Satscape

Weather satellite animated GIF for Raspberry Pi

Jan 21st, 2016
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. # IMPORTANT! This Python script has one dependancy, simply paste this line into the terminal to install it!
  2. # sudo apt-get install imagemagick -y
  3. #
  4. # Next, make a folder on your Raspberry pi:  /home/pi/pyscripts/wxgif/  (you probably have /home/pi/ already!)
  5. # Save this script into that folder.
  6. #
  7. # WXGIF python3 script by Scott Hather - Run this every hour (using Crontab) and it will download the latest
  8. # Weather satellite image of europe, then it grabs the latest 12 captured images and compiles them into
  9. # an animated GIF for your viewing pleasure!
  10.  
  11. from subprocess import call
  12. from subprocess import check_output
  13. import datetime
  14. import os.path
  15. import shutil
  16.  
  17. # first get the hour as an integer
  18. hr=datetime.datetime.now().time().hour
  19. mn=0
  20. fn=str(hr).zfill(2)+str(mn).zfill(2)  # the time in format 1300  1400 etc.
  21.  
  22. # grab this hour's Infra-red satellite image
  23. call("wget --no-cache -O /home/pi/pyscripts/wxgif/wx"+fn+".jpg http://oiswww.eumetsat.org/IPPS/html/latestImages/EUMETSAT_MSG_IR039E-westernEurope.jpg",shell=True)
  24.  
  25. # also, during daylight hours, grab the Visual image too
  26. if hr>=8 and hr <=16:
  27.     call("wget --no-cache -O /home/pi/pyscripts/wxgif/wxv"+fn+".jpg http://oiswww.eumetsat.org/IPPS/html/latestImages/EUMETSAT_MSG_VIS006E-westernEurope.jpg",shell=True)
  28.  
  29. # fiddle with the hours and set things up a bit
  30. xhr=hr-12
  31. if xhr<0:
  32.     xhr=xhr+24
  33.  
  34. jpgfiles=""
  35. jpgfilesv=""
  36. got=""
  37.  
  38. # Compile the last 12 images IR and VIS into animated GIFs
  39. for i in range(0,12):
  40.     xhr=xhr+1
  41.     if xhr >23:
  42.         xhr=xhr-24
  43.     # IR
  44.     ff="wx"+str(xhr).zfill(2)+"00.jpg" 
  45.     fn="/home/pi/pyscripts/wxgif/"+ff
  46.     print("Checking for "+fn)
  47.     if os.path.isfile(fn):
  48.         print("Got "+fn)
  49.         jpgfiles=jpgfiles+fn+" "
  50.     else:
  51.         print(fn+" DOES NOT EXIST, but that's ok")
  52.        
  53.     # VISUAL   
  54.     ffv="wxv"+str(xhr).zfill(2)+"00.jpg"   
  55.     fnv="/home/pi/pyscripts/wxgif/"+ffv
  56.     print("Checking for "+fnv)
  57.     if os.path.isfile(fnv):
  58.         print("Got "+fnv)
  59.         got=fnv
  60.         jpgfilesv=jpgfilesv+fnv+" "
  61.  
  62. #IR Hold last image for 10 frames  
  63. for j in range(0,10):
  64.     jpgfiles=jpgfiles+fn+" "       
  65.  
  66. #VISUAL Hold last image for 10 frames  
  67. for j in range(0,10):
  68.     jpgfilesv=jpgfilesv+got+" "
  69.  
  70. print("Converting to animated gif...")
  71. call("convert -delay 1 -loop 0 "+jpgfiles+"/home/pi/pyscripts/wxgif/latest-anim.gif",shell=True)
  72. if hr>=8 and hr <=17:
  73.     call("convert -delay 1 -loop 0 "+jpgfilesv+"/home/pi/pyscripts/wxgif/latest-animv.gif", shell=True)
  74.  
  75. # All done!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement