[Python] NASA's astronomy picture of the day

just some simple python scripting + crontab

apod.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
import urllib3
import urllib.request as request
import os

PATH='/PICTURE_FOLDER/nasa.jpg'

url = "https://apod.nasa.gov/apod/"
http = urllib3.PoolManager()
p = re.compile(r'(image.*jpg)')

r = http.request('GET',url)


if (r.status == 200):
    html = r.data.decode('utf-8')
    #print(html)
    imgurl = re.findall(p,html)
    try:
        img = imgurl[0]
        download_url = url + img
        print(download_url)
        pic = request.urlretrieve(download_url, PATH)
        print('writing file to ', PATH)

    except Exception as e:
        print("hmmmm something went wrong")

else:
    print("network failure...")

Notes: this script will overwrite history downloads. Only the current APOD is kept on the disk. The filepath can be modified to the picture’s name or date to keep all pictures.

I used both urllib3 and urllib, which is kindda messy…

And here is a bash script that downloads picture and set wallpaper:

1
2
3
4
#!/usr/bin/sh
python ~/scripts/apod.py
echo 'setting bg' 
feh --no-fehbg --bg-scale '/home/shrik3/Pictures/nasa.jpg'

A crontab can be set like:

0 12 * * * nasa_bg
edited 13.01.2023
created 29.05.2020
EOF
[+] click to leave a comment [+]
the comment system on this blog works via email. The button
below will generate a mailto: link based on this page's url 
and invoke your email client - please edit the comment there!

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as   
  anonymous
- your email address will not be disclosed
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.

>> SEND COMMENT <<




the greater struggle via serocell - media feed March 30, 2024

Screenshot: New Device via Detritus March 18, 2024

Idiot's guide to resource migration in Terraform via Archive Fever by Edwin Wenink March 15, 2024
Sometimes we need to migrate resources that are managed in Terraform. Terraform is a declarative language to manage cloud infrastructure from code, which allows you to reliably automate your deployments and put your infrastructure configuration under versi…

Generated by openring from webring