Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:09:43+00:00 2026-06-17T11:09:43+00:00

I’m having quite some trouble doing that : I’m using Conky on my Archlinux

  • 0

I’m having quite some trouble doing that :
I’m using Conky on my Archlinux distro and coded a quick script in python to check if I have a new mail in my gmail. In my conkyrc this script executes every 5 minutes and returns a number of mails (0 if I don’t have any). Works fine.

What I wanted to do is :
If the number of mail is > 0 then display a notification (a gnome-shell notification). The only problem I have now is that if I have unread mails (for example 4 mails unread), each 5 minutes, there will be a NEW notification saying that I have 4 mails unread. What I would like to do is checking if there is already a notification so that I don’t have to display it again… Does anyone know how to solve that kind of problem ?

Here is my code :

#!/usr/bin/python

from gi.repository import Notify
from urllib.request import FancyURLopener

url = 'https://%s:%s@mail.google.com/mail/feed/atom' % ("username", "password")

opener = FancyURLopener()
page = opener.open(url)

contents = page.read().decode('utf-8')

ifrom = contents.index('<fullcount>') + 11
ito   = contents.index('</fullcount>')

unread = contents[ifrom:ito]

print(unread)

if unread != "0" :
    Notify.init ("New Mail")
    Hello=Notify.Notification.new ("New mail","You have "+unread+" new mail(s)","/usr/share/icons/Faenza/actions/96/mail-forward.png")
    Hello.show ()

I must precise that I’m quite new to python. Thanks in advance if anyone got a solution 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:09:46+00:00Added an answer on June 17, 2026 at 11:09 am

    One possible solution is serialise the value of unread into a file.

    Then change your check from if the number of mails is greater than 0, to if the number of mails is greater than zero or different from the last serialised count from file.

    An extension of this is to also serialise the time when a notification is run along with the mail count, this way you extend the check to show the repeat notification (showing 4 emails twice, not every 5 minutes say, but every 3 hours).

    So your original check was if unread != "0" : it would become something like if unread != "0" && unread != serialisedvalue: . In the show repeat notification time threshold case
    it becomes

    if unread != "0":
        if ((datetime.now() - serialiseddate) < threshold) :
            if unread != serialisedvalue:
    

    Where threshold = 3600*3 is for 3 hours.

    Sample code for serialising and deserialising is below

    #Serialising
    try:
        # This will create a new file or **overwrite an existing file**.
        f = open("mailcount.txt", "w")
        try:
            f.write(unread + "\n") # Write a string to a file
            f.write(datetime.now().strftime('%b %d %Y %I:%M%p'))
        finally:
            f.close()
    except IOError:
        pass
    
    #Deserialising 
    try:
        f = open("mailcount.txt", "r")
        try:
            # Read the entire contents of a file at once.
            serialisedvalue = f.readline()
            serialseddate = datetime.strptime(f.readline(), '%b %d %Y %I:%M%p')
        finally:
            f.close()
    except IOError:
        pass
    

    Another possible solution would be to get the current active notification count somehow and add that to your condition, though I couldn’t find a method for doing that using the API that Notify uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.