#!/usr/bin/env python import PySimpleGUIWx as sg import subprocess import re # Import requests (to download the page) import requests import datetime import time # 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' ANNOUCEMENTS = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/issues/142' TRAFFIC = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/graphs/traffic' SEARCH = r'https://github.com/search?o=desc&q=pysimplegui&s=indexed&type=Code' PYPI_STATS = r'https://pepy.tech/project/pysimplegui' 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" # print(soup) findopen = re.compile(r"\d+ Open") # get number of open issues number_open_string = findopen.search(str(soup)).group() num_open_issues = number_open_string[0:number_open_string.index(' ')] # find the first issue in the list by earing for "issue-id-XXXX" soup = str(soup).replace('\n', '') find_first_issue = re.compile(r'#\d+\s+opened') first_issue_string = find_first_issue.search(str(soup)).group() first_issue = first_issue_string[1:first_issue_string.find(' ')] 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, 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 = sg.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() tray.ShowMessage('Starting up...', '{} Issues\n{} First Issue'.format(initial_issue_count, initial_first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, ) 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=poll_frequncy) 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.startswith('View Issues'): sg.PopupNoWait('Refreshing issue data...', auto_close=True, auto_close_duration=3) issues, first_issue = get_num_issues() tray.ShowMessage('Refreshed', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, ) sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item in('Refresh', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED): tray.ShowMessage('Refreshing', 'Old values are\n{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_NOICON ) tray.Update(data_base64=red_x) issues, first_issue = get_num_issues() tray.ShowMessage('Refreshed', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, ) tray.Update(data_base64=logo) # elif menu_item == sg.EVENT_SYSTEM_TRAY_ICON_ACTIVATED: # tray.ShowMessage('Last check', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, ) elif menu_item == sg.EVENT_SYSTEM_TRAY_MESSAGE_CLICKED : tray.Update(data_base64=logo) 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('Announcements'): sp = subprocess.Popen([CHROME, ANNOUCEMENTS], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item.startswith('Traffic'): sp = subprocess.Popen([CHROME, TRAFFIC], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) elif menu_item.startswith('Search'): sp = subprocess.Popen([CHROME, SEARCH], 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) elif menu_item.startswith('PyPI'): sp = subprocess.Popen([CHROME, PYPI_STATS], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 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','---', 'Announcements', 'Traffic', 'PyPI Stats', 'Search for Project' , '&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.PopupNonBlocking('Issues changed on GitHub ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True, grab_anywhere=True) initial_issue_count = issues initial_first_issue = first_issue tray.Update(data_base64=logo32x32red) tray.ShowMessage('Issues changes!', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, ) else: sg.PopupNonBlocking('Update error at: ', datetime.datetime.now(), background_color='red', keep_on_top=True, grab_anywhere=True) print('Update failed', datetime.datetime.now()) seconds += poll_frequncy/1000 red_x = b"R0lGODlhEAAQAPeQAIsAAI0AAI4AAI8AAJIAAJUAAJQCApkAAJoAAJ4AAJkJCaAAAKYAAKcAAKcCAKcDA6cGAKgAAKsAAKsCAKwAAK0AAK8AAK4CAK8DAqUJAKULAKwLALAAALEAALIAALMAALMDALQAALUAALYAALcEALoAALsAALsCALwAAL8AALk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