Демон не отображает требуемый контент, не смотря на статус active

Я написал простой Python скрипт, который обращается к Gmail API раз в несколько секунд и выводит сообщение в уведомление, если оно ранее не было получено.

import the required libraries
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import pickle
import os.path
import base64
import email
import re
from bs4 import BeautifulSoup
import difflib
Peremenaya  = 0
import time
import notify2

# Define the SCOPES. If modifying it, delete the token.pickle file.
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']

def getEmails():
    # Variable creds will store the user access token.
    # If no valid token found, we will create one.
    creds = None
    # The file token.pickle contains the user access token.
    # Check if it exists
    if os.path.exists('/home/kali/Desktop/Python_code/token.pickle'):

        # Read the token from the file and store it in the variable creds
        with open('/home/kali/Desktop/Python_code/token.pickle', 'rb') as token:
            creds = pickle.load(token)

    # If credentials are not available or are invalid, ask the user to log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file('/home/kali/Desktop/Python_code/credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)

        # Save the access token in token.pickle file for the next run
        with open('/home/kali/Desktop/Python_code/token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    # Connect to the Gmail API
    service = build('gmail', 'v1', credentials=creds)
    # request a list of all the messages
    #result = service.users().messages().list(userId='me').execute()
    # We can also pass maxResults to get any number of emails. Like this:
    result = service.users().messages().list(maxResults=1, userId='me').execute()
    messages = result.get('messages')
    # messages is a list of dictionaries where each dictionary contains a message id.
    # iterate through all the messages
    for msg in messages:
        # Get the message from its id
        txt = service.users().messages().get(userId='me', id=msg['id']).execute()
        # Use try-except to avoid any Errors
        try:
            # Get value of 'payload' from dictionary 'txt'
            payload = txt['payload']
            headers = payload['headers']

            # Look for Subject and Sender Email in the headers
            for d in headers:
                if d['name'] == 'Subject':
                    subject = d['value']
                if d['name'] == 'From':
                    sender = d['value']
            # The Body of the message is in Encrypted format. So, we have to decode it.
            # Get the data and decode it with base 64 decoder.
            parts = payload.get('parts')[0]
            data = parts['body']['data']
            data = data.replace("-","+").replace("_","/").replace("<p>","")
            decoded_data = base64.b64decode(data)
            # Now, the data obtained is in lxml. So, we will parse
            # it with BeautifulSoup library
            soup = BeautifulSoup(decoded_data , "lxml")
            body = soup.body()
            text = soup.get_text()
            new = 'Отправитель:' + ' ' + str(sender) + "\n" + text
            global Peremenaya
            if Peremenaya == 0:
                Peremenaya = text
                print('''It's first try ''')
            # Printing the subject, sender's email and 
            if Peremenaya != text:
                #print("Subject: ", subject)
                #print("From: ", sender)
                #print("Message: ", text)
                notify2.init('foo')
                n = notify2.Notification('Новое сообщение',new)
                n.show()
                Peremenaya = text

        except:
            pass

while True:
    getEmails()
    time.sleep(6)   

При запуске через консоль программа прекрасно работает введите сюда описание изображения

Но при запуске демона любым способом ничего не происходит введите сюда описание изображения

Настройки демона введите сюда описание изображения


Ответы (0 шт):