Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 06/08/2020, à 16:14

Saturnin51

[Résolu]Application au démarrage ne s'exécute plus

Bonjour,

dans les Application au démarrage, j'ai une commande "/home/robert/.apod/sh apod-wallpaper.sh" qui doit s'exécuter chaque fois que l'ordi démarre. Or depuis quelque temps (??) elle ne s'exécute plus automatiquement. Je dois le faire manuellement. Une idée d'où cela peut provenir SVP ?

Dernière modification par Saturnin51 (Le 08/03/2021, à 22:42)

Hors ligne

#2 Le 06/08/2020, à 16:22

xubu1957

Re : [Résolu]Application au démarrage ne s'exécute plus

Bonjour,

La NASA ? > projectAPOD ?


Conseils pour les nouveaux demandeurs et pas qu'eux
Important : Pensez à passer vos sujets en [Résolu] lorsque ceux-ci le sont, au début du titre en cliquant sur Modifier sous le premier message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.                   Membre de Linux-Azur

En ligne

#3 Le 06/08/2020, à 18:24

erresse

Re : [Résolu]Application au démarrage ne s'exécute plus

Bonjour,
As-tu cette image de générée dans ton répertoire personnel, et de quand date-t-elle ?

$HOME/.apod/apod.png

Si elle a bien été générée, c'est que le script fonctionne et qu'elle n'est pas affichée par ton système, le site du projet indique :

site du projet APOD a écrit :

Just configure your desktop with this image as background. You never need to change it. The software will replace the file every day with the new image and your desktop will change consequently.
Traduction:
Configurez simplement votre bureau avec cette image en arrière-plan. Vous n'avez jamais besoin de le changer. Le logiciel remplacera le fichier chaque jour par la nouvelle image et votre bureau changera en conséquence.


Plus de 50 ans d'informatique, ça en fait des lignes de commandes en console, mais on n'avait pas le choix...
Excellente raison pour, aujourd'hui qu'on le peut, utiliser au maximum les INTERFACES GRAPHIQUES !
Important : Une fois résolu, pensez à clore votre sujet en ajoutant [Résolu] devant le titre du 1er message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.

Hors ligne

#4 Le 07/08/2020, à 15:54

Saturnin51

Re : [Résolu]Application au démarrage ne s'exécute plus

Non l'image n'est pas générée. J'ai celle du 1er Août que j'ai obtenu manuellement. Ce n'est pas celui de la NASA. Je ne le trouve plus sur le Net. C'est un simple script:

#!/bin/sh  -xv
#
# downloads today's Astronomy Picture of the Day
# and sets it as wallpaper
#
# Adjust SCREEN_GEOMETRY for your needs
#
# Version 1.8
# A. Dominik, 19. Jun 2016

sleep 2

#SCREEN_GEOMETRY="1920x1200"
APOD_URL="http://apod.nasa.gov/apod/"
FILE_URL="http://apod.nasa.gov/apod/astropix.html"
ORIGINAL="raw.html"
ORI_NO_HEAD="raw-no-head.html"
IMAGE_URL="http://dummy.jpg"
IMAGE_NAME="dummy.jpg"

WALLPAPER_NAME="apod.png"
WALLPAPER_TEMP_NAME="temp.png"
WALLPAPER_TXT="apod.txt"

IMAGE_TITLE="dummy"
IMAGE_TITLE_FILE="title.txt"
IMAGE_EXPL="dummy"
IMAGE_EXPL_FILE="explanation.txt"

HOME_DIR=$HOME
WORK_DIR="${HOME}/.apod"

TEMP1="tempfile1"
TEMP2="tempfile2"
TEMP3="tempfile3"

#
# Read config file:
#
. ${WORK_DIR}/apod-wallpaper.config


#
# Check for working dir:
if ! test -d $WORK_DIR
then
  echo "Directory $WORK_DIR not found"
  exit
fi

cd $WORK_DIR

#
# check for internet connection:
#
wget www.google.com

I_NET=$?

if ! test $I_NET -eq 0
then
  echo "No internet connection"
  exit
fi

#
# test for a filename to download
#
if test $# -gt 0
then
  FILE_URL="$1"
fi


#
# get html page
#
wget $FILE_URL -O $ORIGINAL

#
# extract image url
# extract image name
# and download hi-res image
#
IMAGE_URL=$(cat $ORIGINAL | grep 'href="image' | head -1 | \
                            sed 's/<a href="/  /g' | sed 's/"/ /g' | sed 's/>/ /g' |\
                            awk '{print( "http://apod.nasa.gov/" $1)}')

IMAGE_NAME=$(echo $IMAGE_URL | sed 's+/+ +g' | awk '{print( $NF)}' | sed 's/\"//g')

wget $IMAGE_URL -O $IMAGE_NAME

#
# extract title
# and remove html tags
#
# The following part of the code tries to find the lines in the APOD HTML 
# page, that holds title and explanation.
# Due to slight changes of the file format, it may not work properly for 
# all historic APOD pages.
#
# make files nice
# Some HTML tags lower:
#
cat $ORIGINAL | \
sed 's/<CENTER>/<center>/g;s/<\/CENTER>/<\/center>/g;s/<B>/<b>/g;s/<\/B>/<\/b>/g' > $TEMP1

# Add line breaks after center tags:
#
cat $TEMP1 | \
sed 's/<center><b>/<center>\n<b>/g' > $TEMP2

# Add line breaks after word Explanation:
#
cat $TEMP2 | \
sed 's/Explanation<\/b>/Explanation\n<\/b>/g;s/Explanation:<\/b>/Explanation:\n<\/b>/g;' > $TEMP1

# Remove empty lines
#
cat $TEMP1 | awk NF > $TEMP2
cp $TEMP2 $TEMP1

# Remove page header
# del all up to image link
#
cat $TEMP1 | \
awk 'BEGIN {MOD = 0} { if (MOD==1) {print}; if ($0 ~ "href=\"image") {MOD = 1}}' | \
awk 'NR>2 { print }' > $ORI_NO_HEAD
  
# del all up to 2nd center
cat $ORI_NO_HEAD | \
awk 'BEGIN {MOD = 0} { if (MOD==1) {print}; if ($0 ~ "<center>") {MOD = 1}}' > $TEMP1

# Extract line with title and
# trim title; i.e. remove html, trim and remove line breaks
#
cat $TEMP1 | awk 'NR==1 {print}' > $TEMP2
cat $TEMP2 | sed 's/<[^>]*>//g;s/^ *//g;s/ *$//g;s/ \{1,\}/ /g;s/[\n\r]/ /g' > $IMAGE_TITLE_FILE

cat $IMAGE_TITLE_FILE

#
# extract explanation
# and remove html tags
#
# del all up to 1st Explanation
#
cat $ORI_NO_HEAD | \
awk 'BEGIN {MOD = 0} { if (MOD==1) {print}; if ($0 ~ "Explanation") {MOD = 1}}' > $TEMP1

# del all from next center
cat $TEMP1 | \
awk 'BEGIN {MOD = 1} { if ($0 ~ "<center>") {MOD = 0}; if (MOD==1) {print}}' > $TEMP2

# remove html, line breaks and unneeded spaces:
#
cat $TEMP2 | tr '\012' ' ' |  tr '\015' ' ' | \
  sed 's/<[^>]*>//g;s/^ *//;s/ *$//;s/ \{1,\}/ /g' > $IMAGE_EXPL_FILE

cat $IMAGE_EXPL_FILE

#
# create annotated image with imagemagick
#
convert $IMAGE_NAME ^ $IMAGE_NAME
convert $IMAGE_NAME -gravity center +0+0 $IMAGE_NAME

convert $IMAGE_NAME -fill white -pointsize 12 -gravity SouthWest -annotate +10+2 "$(cat explanation.txt)" -pointsize 20 -annotate +10+15 "$(cat title.txt)" $IMAGE_NAME

composite -gravity NorthEast -geometry +0+100 ubuntu-550.png $IMAGE_NAME $WALLPAPER_TEMP_NAME
if test -s $WALLPAPER_TEMP_NAME
then
  mv $WALLPAPER_TEMP_NAME $WALLPAPER_NAME
fi




#
# create text file with annotation:
#
IMAGE_ANNOTATION_TXT="${IMAGE_NAME}.txt"
echo "$IMAGE_NAME"         > $IMAGE_ANNOTATION_TXT
echo "\n Title: "         >> $IMAGE_ANNOTATION_TXT
cat $IMAGE_TITLE_FILE     >> $IMAGE_ANNOTATION_TXT
echo "\n Explanation: "   >> $IMAGE_ANNOTATION_TXT
cat $IMAGE_EXPL_FILE      >> $IMAGE_ANNOTATION_TXT

# Remove all temporary files:
#
rm -f $TEMP1 $TEMP2 $TEMP3
rm -f $ORIGINAL $ORI_NO_HEAD
rm -f $IMAGE_TITLE_FILE $IMAGE_EXPL_FILE
rm -r $IMAGE_NAME $WALLPAPER_TEMP_NAME
mv $IMAGE_ANNOTATION_TXT $WALLPAPER_TXT
rm -f index.*

#
# Set as wallpaper (Gnome):
#
# gconftool-2 -t str --set /desktop/gnome/background/picture_filename "${WORK_DIR}/${WALLPAPER_NAME}"
# gsettings set org.gnome.desktop.background picture-uri "file://$(pwd)/${WALLPAPER_NAME}"
#
# rm ${HOME_DIR}/.cache/wallpaper/*
cp "$(pwd)/${WALLPAPER_NAME}" "${HOME}/Wallpapers/apod.png"
sleep 2
gsettings set org.gnome.desktop.background picture-uri "file:$(pwd)/${WALLPAPER_NAME}"
# gsettings set org.gnome.desktop.background picture-uri "file://$(pwd)/${WALLPAPER_NAME}"
# gsettings set org.gnome.desktop.background picture-uri "file:///$(pwd)/${WALLPAPER_NAME}"

Dernière modification par Saturnin51 (Le 07/08/2020, à 16:01)

Hors ligne

#5 Le 07/08/2020, à 16:40

erresse

Re : [Résolu]Application au démarrage ne s'exécute plus

Saturnin51 a écrit :

Ce n'est pas celui de la NASA. Je ne le trouve plus sur le Net. C'est un simple script:

Bien sûr que c'est un simple script, et ce que tu as listé est bien le script qu'on télécharge dans une archive "apod_wallpaper-v1.8.tar.gz" sur le site de la NASA...
Normalement, l'exécution de ce script devrait aller chercher sur leur site l'image du jour et l'enregistrer sur ta machine en "${HOME}/Wallpapers/apod.png" (et non, comme indiqué par la doc "$HOME/.apod/apod.png"). Est-ce cette image que tu as consulté (qui date du 1er août) ?
Note: Je constate à la lecture de la page du site de la NASA, que certains chemins ou fichiers ont pu changer de noms... Est-ce que tu as rechargé récemment l'archive ou en utilises-tu une plus ancienne ? Peut-être faut-il mettre à jour pour cadrer avec la dernière version.


Plus de 50 ans d'informatique, ça en fait des lignes de commandes en console, mais on n'avait pas le choix...
Excellente raison pour, aujourd'hui qu'on le peut, utiliser au maximum les INTERFACES GRAPHIQUES !
Important : Une fois résolu, pensez à clore votre sujet en ajoutant [Résolu] devant le titre du 1er message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.

Hors ligne

#6 Le 14/08/2020, à 18:37

Saturnin51

Re : [Résolu]Application au démarrage ne s'exécute plus

En fait il me manquait Imagemagick. Après installation le script fonctionne. Merci de ton aide.

Hors ligne

#7 Le 08/09/2020, à 11:20

Saturnin51

Re : [Résolu]Application au démarrage ne s'exécute plus

Je reviens sur le sujet car j'ai toujours le même problème mais avec le script de la NASA, desktop_nasa.0.7.py. Il est dans mes applications au démarrage mais ne semble pas s'exécuter, puisque l'arrière-plan ne change pas. En fait l'image est généré dans le répertoire /home/robert/stathis/.background mais pas affichée.

#!/usr/bin/env python
"""
desktop_nasa.py

DESCRIPTION
Gets the latest image of the day from NASA, http://apod.nasa.gov/apod/,
gets the description for that image, resize image, write description to it
and set it as the background in Gnome.

INSTALLATION
To make this work you will need to set a valid font path, a download folder
which should exist and change the resolution variables to that of your screen.
Furthermore if you want this to automatically update your desktop you should add
this script to cron jobs, or to startup applications. Also download all needed
python libraries.

ON UBUNTU JUST RUN

sudo apt-get install python-imaging

then go to
System -> Preferences -> Startup Applications
then add script like this
python /dir/to/script/desktop_nasa.x.x.py

ALSO SET VARIABLE
DOWNLOAD = '/home/stathis/.backgrounds/'
to a directory that script can use

For any suggestions, improvements, bugs feel free to contact me at
stmayridopoulos@hotmail.com

Based on a script of Christian Stefanescu, http://0chris.com

intelli_draw method from:
http://mail.python.org/pipermail/image-sig/2004-December/003064.html
"""
import commands
import urllib
import urllib2
import re
import os
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import time
import subprocess

# Configurable Settings
# FONTS
FONT_PATH = '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf'
FONT_SIZE = 20
FONT_COLOR = (255, 255, 255)
# Select False if you don't want any description
GET_IMAGE_ONLY = False
# Future Option
# Valid values are [top, bottom, left, right]
# text_positioning = 'top'
NASA_POD_SITE = 'http://apod.nasa.gov/apod/'
# IMPORTANT, SET THIS VARIABLE TO A DIR THAT EXISTS AND SCRIPT CAN WRITE
DOWNLOAD = '/home/robert/stathis/.backgrounds/'
RESOLUTION_X = 1680
RESOLUTION_Y = 1050

# globals
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)


# FUNCTIONS

def download_site(url):
    ''' Download contents from url and return it. '''
    opener = urllib2.build_opener()
    req = urllib2.Request(url)
    response = opener.open(req)
    reply = response.read()
    return reply

def get_img_title(text):
    ''' Get the image title from site contents. '''
    ret_value = ''
    title_regex = '\<b\> (.*?) \<\/b\>'
    try:
        reg = re.search(title_regex, text)
    except sre_constants.error:
        pass
    try:
        ret_value = reg.group(1)
    except AttributeError:
        pass
    return ret_value
    

def get_img_description(text):
    ''' Get the image description from site contents. '''
    descr_regex = '\<b\> Explanation: \<\/b\>(.*)\<p\> \<center\>'
    try:
        reg = re.search(descr_regex, text, re.DOTALL)
    except sre_constants.error:
        pass
#   Next filter links, \', newline character before returning
    try:
        raw_descr = reg.group(1)
    except AttributeError:
        return ''
# Delete Newline characters
    ret_value = re.sub('\n',' ', raw_descr)
# Delete all html tags
    ret_value = re.sub('\<.*?\>', '', ret_value)
# Ignore multiple spaces
    ret_value = re.sub('\s+', ' ', ret_value)
    return ret_value

def get_image(text):
    ''' Get image url from text and save it to an temp image file. 
        Return both filenames, temp and real. '''
    reg = re.search('<a href="(image.*?)"',text, re.DOTALL)
    if 'http' in reg.group(1):
        # Contains url
        file_url = reg.group(1)
    else:
        # Contains relative img path
        file_url = NASA_POD_SITE + reg.group(1)
    filename = os.path.basename(file_url)
    remote_file = urllib.urlopen(file_url)
    (temp_filename, instance) = urllib.urlretrieve(file_url)
# Maybe use wget instead? No problems so far though
#    temp_filename = DOWNLOAD + 'tmp_pic'
#    subprocess.check_call(["wget", "-nv", "-O", temp_filename, 
#                            file_url],
#                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return temp_filename, filename

def intelli_draw(drawer, text, font, containerWidth):
    ''' Figures out how many lines (and at which height in px) are needed to 
        print
        the given text with the given font on an image with the given size.

        Source:
        http://mail.python.org/pipermail/image-sig/2004-December/003064.html
    '''
    words = text.split()
    lines = []
    lines.append(words)
    finished = False
    line = 0
    while not finished:
        thistext = lines[line]
        newline = []
        innerFinished = False
        while not innerFinished:
            if drawer.textsize(' '.join(thistext), font)[0] > containerWidth:
                newline.insert(0, thistext.pop(-1))
            else:
                innerFinished = True
        if len(newline) > 0:
            lines.append(newline)
            line = line + 1
        else:
            finished = True
    tmp = []
    for i in lines:
        tmp.append(' '.join(i))
    lines = tmp
    (width, height) = drawer.textsize(lines[0], font)
    return (lines, width, height)

def create_image_text(save_to, temp_image, text):
    '''  '''
    image = Image.open(temp_image)
    (img_width, img_height) = image.size
    # resize to desktop resolution
    # should keep propotions of original image!
    prop_x = float(RESOLUTION_X) / img_width
    prop_y = float(RESOLUTION_Y) / img_height
    prop = min(prop_x, prop_y)
    # Those are the resolutions of the new image
    res_x = int(img_width * prop)
    res_y = int(img_height * prop)
    image = image.resize((res_x, res_y), Image.ANTIALIAS)
    # Add a black background
    background = Image.new('RGB', (RESOLUTION_X, RESOLUTION_Y), (0, 0, 0))
    bg_w, bg_h = background.size
    offset = ((bg_w - res_x) / 2, (bg_h - res_y) / 2)
    background.paste(image, offset)
    if text == '':
        # we just want the image
        pass
    else:
        # I don't want text to occupy image from edge to edge
        text_margin = 0.025  # 10% left and 10% right
        (img_width, img_height) = background.size
        text_margin_pix = text_margin * img_width
        img_width = int( img_width - 2 * text_margin_pix)
        draw = ImageDraw.Draw(background)
        lines, tmp, h = intelli_draw(draw, text, font, img_width)
        j = 0
        for i in lines:
            draw.text((0 + text_margin_pix, 0 + j * h + text_margin_pix),  # where to draw (start @ (0,0))
                    i,  # actual line
                    font=font,  # font to use
                    fill=FONT_COLOR)  # text color
            j = j + 1
    fhandle = open(save_to, 'w')
    background.save(fhandle, 'JPEG')

def set_gnome_wallpaper(file_path):
    command = "gsettings set org.gnome.desktop.background picture-uri file://" + file_path
    status, output = commands.getstatusoutput(command)
    return status
    

if __name__ == '__main__':
    if not os.path.exists(os.path.expanduser(DOWNLOAD)):
        os.makedirs(os.path.expanduser(DOWNLOAD))
    site_contents = download_site(NASA_POD_SITE)
    if GET_IMAGE_ONLY == False:
        title = get_img_title(site_contents)
        title = title + ': '
        description = get_img_description(site_contents)
    else:
        title = ''
        description = ''
    temp_filename, filename = get_image(site_contents)
    create_image_text(DOWNLOAD + filename, temp_filename, title + description)
    status = set_gnome_wallpaper(DOWNLOAD + filename)

Merci d'avance pour aide.

Dernière modification par Saturnin51 (Le 08/09/2020, à 12:13)

Hors ligne

#8 Le 24/09/2020, à 11:51

Saturnin51

Re : [Résolu]Application au démarrage ne s'exécute plus

Je relance ce sujet car quelque soit le script que je mets dans Applications au démarrage, il ne s'exécute pas depuis le changement de version en 2020.04. Une idée ?

Hors ligne