#!/usr/bin/env python from PySimpleGUIWx import SystemTray from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_ACTIVATED from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_RIGHT_CLICK from PySimpleGUIWx import EVENT_SYSTEM_TRAY_MESSAGE_CLICKED import PySimpleGUIWx as sgwx import PySimpleGUI as sg import subprocess import re # Import requests (to download the page) import requests import datetime # Import BeautifulSoup (to parse what we download) from bs4 import BeautifulSoup # CCNSTANTS - CHANGE THESE TO MATCH YOUR SYSTEM CHROME = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" DISCORD = r"C:\Users\mike\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Discord Inc\Discord.lnk" VIEW_ISSUES_URL = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc' PULL_REQUEST_URL = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/compare/master...Dev-latest' ICON_FILE = r'C:\Python\PycharmProjects\GooeyGUI\default_icon.ico' # search github for total open issues and Issue Number of first issue def get_num_issues(): url = "https://github.com/MikeTheWatchGuy/PySimpleGUI/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc" # set the headers like we are a browser, headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} # download the page requests.adapters.DEFAULT_RETRIES = 25 try: response = requests.get(url, headers=headers) except: return 0,0 # parse the downloaded homepage and grab all text, soup = BeautifulSoup(response.text, "lxml") # look for phrase "XXX Open" findopen = re.compile(r"\d+ Open") # get number of open issues number_open_string = findopen.search(str(soup)).group(0) num_open_issues = number_open_string[0:number_open_string.index(' ')] # find the first issue in the list by earing for "issue-id-XXXX" find_first_issue = re.compile(r'issue-id-\d+') first_issue_string = find_first_issue.search(str(soup)).group(0) first_issue = first_issue_string[9:] return num_open_issues, first_issue def gui(): sg.ChangeLookAndFeel('Topanga') sg.SetOptions(border_width=0) layout = [ [sg.T('GitHub Issues Watcher' + 5 * ' ', click_submits=True, key='GitHub'), sg.Button('', size=(25,25), image_data=red_x, key='_quit_',button_color=(sg.LOOK_AND_FEEL_TABLE['Topanga']['TEXT'],sg.LOOK_AND_FEEL_TABLE['Topanga']['BACKGROUND']), tooltip='Closes window')], [sg.T('', key='_status_', size=(12, 1))], [sg.T('', key='_numissues_', size=(20, 1))], ] window = sg.Window('Issue watcher', no_titlebar=True, grab_anywhere=True, keep_on_top=True, alpha_channel=.8, # dim the lights a little location=(2360,310), # locate in upper right corner of screen ).Layout(layout).Finalize() window.Refresh() status_elem = window.FindElement('_status_') issues_elem = window.FindElement('_numissues_') initial_issue_count, initial_first_issue = get_num_issues() seconds = 0 poll_frequncy = 1000 while True: event, values = window.Read(timeout=poll_frequncy) if event in ('_quit_', None): break if seconds % 60 == 0 or event.startswith('GitHub'): # Every 60 seconds read GitHub status_elem.Update('Reading...') window.Refresh() issues, first_issue = get_num_issues() if issues == 0 and first_issue == 0: print('Read error', time.time()) continue issues_elem.Update('{} Issues. {} is first issue'.format(issues, initial_first_issue)) window.Refresh() # if something changed, then make a popup if issues != initial_issue_count or first_issue != initial_first_issue: sg.PopupNoWait('Issues changed on GitHub ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True) initial_issue_count = issues initial_first_issue = first_issue status_elem.Update('') else: status_elem.Update('.' if seconds%2 else '') # blink a '.' every 2 seconds so know still running seconds += poll_frequncy/1000 window.Close() def system_tray(): menu_def = ['Root', ['E&xit']] tray = SystemTray(menu=menu_def, data_base64=logo, tooltip='GitHub Issue Watcher') # tray = SystemTray(menu=menu_def, filename= ICON_FILE, tooltip='GitHub Issue Watcher') # tray.Hide() initial_issue_count, initial_first_issue = get_num_issues() issues = first_issue = 0 # The Event Loop runs every 5000ms poll_frequncy = 5000 seconds = 0 print('Starting', datetime.datetime.now()) while True: menu_item = tray.Read(timeout=2000) if menu_item == 'Exit': break if menu_item == 'Run GUI': tray.Update(data_base64=red_x) gui() tray.Update(data_base64=logo) elif menu_item == EVENT_SYSTEM_TRAY_ICON_ACTIVATED: tray.ShowMessage('Issue', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sgwx.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, ) if seconds % 12 == 0: # Every 60 seconds read GitHub issues, first_issue = get_num_issues() if issues != 0: menu_def = ['root', ['{} Issues'.format(issues), '{} First Issue'.format(first_issue), '---','&View Issues Online', '&Pull Request','&Discord', '---','&Run GUI', '&Refresh', 'E&xit']] tray.Update(menu_def, tooltip='{} First Issue'.format(first_issue)) # if something changed, then make a popup if issues != initial_issue_count or first_issue != initial_first_issue: sg.Popup('Issues changed on GitHub ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True) initial_issue_count = issues initial_first_issue = first_issue else: print('Update failed', datetime.datetime.now()) if menu_item in('Refresh', EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED): issues, first_issue = get_num_issues() tray.ShowMessage('Issue', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sgwx.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, ) sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item == EVENT_SYSTEM_TRAY_MESSAGE_CLICKED or menu_item.startswith('View Issues'): sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item.startswith('Pull'): sp = subprocess.Popen([CHROME, PULL_REQUEST_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item.startswith('Discord'): sp = subprocess.Popen([DISCORD, r''], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) seconds += poll_frequncy/1000 red_x = b"R0lGODlhEAAQAPeQAIsAAI0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