def setup_notify_run(): """ Function to create a new notify-run channel. Returns the endpoint URL. """ # Setup notify run channel and print info notify = Notify() notify.register() print(notify.info()) # Save channel endpoint to file save_notify_run_settings(notify) return notify.endpoint
def find_slots(zipcode: str): result = requests.get(BASE_URL + zipcode) data = result.json() cur_week = datetime.now().isocalendar()[1] data = data.get("_embedded").get("lanes")[3].get("_embedded").get( "items")[0].get("_embedded") total_slots = 0 for day in data.get("deliveryDates"): date = datetime.strptime(day['date'], "%Y-%m-%d") if date.isocalendar()[1] == cur_week: r = 0 for slot in day['deliveryTimeSlots']: if slot['state'] != "full": r += 1 total_slots += r if total_slots > 0: notify = Notify() if notify.config_file_exists: notify.read_config() else: print(notify.register()) notify.write_config() print("[" + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + "] Notifying about " + str(total_slots) + " available slots") notify.send("AH Bezorg slots beschikbaar", "https://www.ah.nl")
def register_notify(): reg = Notify() print('Register at {}'.format(reg.register().endpoint)) input('Press Enter after registration') with open('resources/registered.txt', 'w+') as output_file: output_file.write('1')
def check_for_tweets(): twitter = Twitter(os.path.join(BASE_DIR, CONFIG_FILE)) try: # Check which tweets have already been processed with open(os.path.join(BASE_DIR, "prev_id"), "r") as file: prev_id = int(file.read()) except FileNotFoundError: # File 'prev_id' does not exist, set it as his most recent tweet tweets = twitter.get_tweets_from_user(PROJECT_SETTINGS['elonHandle']) prev_id = tweets[0].id # Load the keywords we are checking for with open(os.path.join(BASE_DIR, "keywords"), "r") as file: keys = file.read() keywords = keys.split("\n") # Load tweets tweets = twitter.get_tweets_from_user_since(PROJECT_SETTINGS['elonHandle'], prev_id) # Check the tweets for keywords found = set() max_id = prev_id for tweet in tweets: id = tweet.id txt = str(tweet.text).lower() for key in keywords: if key in txt: found.add(key) if id > max_id: max_id = id # Save our progress with open(os.path.join(BASE_DIR, "prev_id"), "w") as file: file.write(str(max_id)) # Notify if necessary if len(found) > 0: msg = "Elon Tweeted about the following topics: '" + ", ".join( found) + "'" notify = Notify() if notify.config_file_exists: notify.read_config() else: print(notify.register()) notify.write_config() print("[" + str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + "] Sending notification: " + msg) notify.send( msg, "https://www.twitter.com/" + PROJECT_SETTINGS['elonHandle'])
def register_notify_channel(): notify = Notify() if config.has_option('notify-run', 'channel'): notify.endpoint = 'https://notify.run/' + config['notify-run'][ 'channel'] main_logger.info( 'Will use self provided channel: https://notify.run/c/' + config['notify-run']['channel']) elif notify.config_file_exists: main_logger.info( 'Will use notify-run saved config: https://notify.run/c/' + notify.endpoint[19:]) else: main_logger.info( 'Neither my own nor notify-run config channel was found. Will register new...' ) main_logger.info(notify.register()) return notify
class Notifier(object): def __init__(self, remote_notifications=False): self._local_notifier = LocalNotify() if remote_notifications: self._remote_notifier = RemoteNotify() logger.info( "Registering a new Remote Push Notification (RPN) endpoint") remote_notify_info = self._remote_notifier.register() self._display_remote_notify_info(str(remote_notify_info)) else: self._remote_notifier = None @classmethod def _display_remote_notify_info(cls, remote_notify_info): if os.name == 'nt': # Windows cmd/powershell does not display QR code properly - stripping it off remote_notify_info = remote_notify_info[:remote_notify_info.index( "Or scan this QR code")] logger.info( """\n\n****************** REMOTE PUSH NOTIFICATIONS ********************\n %s \nNOTE: iOS and Safari NOT supported \n*****************************************************************\n""", remote_notify_info ) def notify(self, title, message, link): if self._remote_notifier: self._send_remote_notification(title, message, link) else: self._send_local_notification(title, message) def _send_local_notification(self, title, message): self._local_notifier.title = title self._local_notifier.message = message self._local_notifier.send() def _send_remote_notification(self, title, message, link): self._remote_notifier.send( "{title} - {message}".format(title=title, message=message), link)
args.hospitalcode, args.ssn) fl = FilterList(services) f = DateFilter() f.setGreaterThan(DateConverter.today()) f.setSmallerThan(DateConverter.today() + DateConverter.delta(7)) fl.addFilter(f) results = fl.getFiltered() for result in results: print(result) #python fastcup.py --notify --servicecode P3039 --priority D --hospitalcode 30063 --ssn <AAABBB12X34Y567Z> if args.notify: notify = Notify() qr = notify.register() secs = 120 if args.seconds: secs = args.seconds print( "Please subscribe to this push channel to receive notification directly on your device (pc, phone, ...)" ) print(qr) input("Press Enter to continue...") while True: c = CUP()
def subscribe(self): #notify-run script notify = Notify() end = notify.register() endP = str(end) webbrowser.open((endP.split('open: ')[1]).split('\n')[0])
from bs4 import BeautifulSoup import pandas as pd import numpy as np import requests import tqdm import re from tqdm import tqdm from notify_run import Notify import csv from csv import writer notify = Notify() print(notify.register()) url_names = 'https://www.maxpreps.com/rankings/baseball-spring-18/{}/national.htm' url_scores = 'https://www.maxpreps.com/high-schools/{})/baseball-spring-18/schedule.htm' url_contact_info = 'https://www.maxpreps.com/high-schools/{})/home.htm' #state_set = ['california','colorado','illinois','iowa','kentucky','new-hampshire','new-jersey','new-mexico','south-dakota','tennessee'] school_name = [] #518 pages for x in tqdm(range(0, 2, 1)): names = url_names.format(x) r = requests.get(names) sopa = BeautifulSoup(r.text, 'html.parser') for item in sopa.find_all('tr'): try: school_name.append( item.find('th', attrs={ 'class': 'school', 'scope': 'row' }))
from bs4 import BeautifulSoup from selenium import webdriver from time import sleep from webbrowser import open_new from notify_run import Notify found_product = False expected_price = "£1,019.00" expected_name = "Refurbished 13.3-inch MacBook Air Apple M1 Chip with 8‑Core CPU and 7‑Core GPU - Space Grey" refurb_url = "https://www.apple.com/uk/shop/refurbished/mac/2020-13-inch-macbook-air" notify = Notify() channel = notify.register() # output notification url, wait for user to start program print(channel.endpoint) input("Press any key once connected...") # while product has not been found, keep running while not found_product: # wait 5 mins, open refurb webpage via chrome and minimise # note: headless window appears to not work for apple website sleep(5 * 60) driver = webdriver.Chrome() driver.get(refurb_url) driver.minimize_window() # wait 5 seconds for data to load, then grab source sleep(5) source = driver.page_source
get_ipython().run_line_magic('load_ext', 'jupyternotify') # test #%notify #import time #time.sleep(5) # %% from notify_run import Notify # %% notify = Notify() # %% notify.register() # %% import re, glob, os from collections import defaultdict from pathlib import Path import pandas as pd import numpy as np from tqdm import tqdm import math # %% # ver. 3 - debugging the count of regexes. ### NOTE ### # - The code counts terms twice, if they are similar within the same pass. This means that drunk* and drun* count 1 and 2, because the loop counts drunk* again on the second iteration. THIS IS A PROBLEM WITH DRUNK* AND DRUNKARD!!!
import requests import json from bs4 import BeautifulSoup import webbrowser import backgroundruns from notify_run import Notify from subprocess import call notify=Notify() sp=' ' print('choose a category by number: \n [1] phones and tablets ',sp,'[2] electronics',sp,'[3] computing') print(' [4] home and office',sp,'[5] health and beauty',sp,'[6] grocery \n [7] carrefour shop',sp,'[8] baby products',sp,'[9] fashion') print(' [0] search whole website',sp,'[11]observe product') argument=int(input()) print('if prompted to Overwrite existing configuration press Y\n') notifylink=notify.register().endpoint print(notifylink) def pageandsoup(page): soup = BeautifulSoup(page.text, 'html.parser') # print(soup) item = soup.find(class_="products -mabaya") try: itemlist = item.find_all(class_="sku -gallery") except AttributeError: print('\n\nError: Product count is 0.\n Please check the price range and retry') exit() print('product count = ',len(itemlist)) data=[] for item in itemlist: Jmitem={} title=item.find(class_='title')
from notify_run import Notify notify = Notify() info = str(notify.register()) f = open('config.txt', 'w') f.write(info) f.close() _ = input()
from notify_run import Notify notify = Notify() result = notify.register() print(result)
def main(): change_settings = False main_window, load_data_popup, settings = None, None, load_settings(SETTINGS_FILE, DEFAULT_SETTINGS) DEBUG_MODE = settings['debug'] while True: if main_window is None: main_window = create_main_window(settings) #gc.collect() if load_data_popup is None: load_data_popup = create_load_data_popup(settings) #gc.collect() event, values = main_window.read() #print('event: %s\nvalues: %s' % (event, values)) if event == ('Exit'): main_window.close() main_window = None #gc.collect() break if event in ('Settings'): # close main window main_window.close() main_window = None #gc.collect() settings_window = create_settings_window(settings) while True: event, values = settings_window.read() print(event) print(values) if event in (None, 'Quit', 'Cancel'): settings_window.close() settings_window = None #gc.collect() break # break # if event in ('Cancel'): # settings_window.close() if event == 'Default Settings': settings_window.close() ##gc.collect() # default settings default_settings(SETTINGS_FILE) settings = load_settings(SETTINGS_FILE, DEFAULT_SETTINGS) if event == 'Save': # for some reason values does not contain the key for Text elements values['-NOTIFYLINK-'] = settings_window['-NOTIFYLINK-'].DisplayText settings_window.close() settings_window = None #gc.collect() save_settings(SETTINGS_FILE, settings, values, popup=True) change_settings = True break print(load_setting(SETTINGS_FILE, 'notify')) if event == '-NOTIFY-': # register using notify-run if values['-NOTIFY-'] and not load_setting(SETTINGS_FILE, 'notify'): notify = Notify() endpointinfo = notify.register() endpointlink = str(endpointinfo).split('\n')[0][10:] settings_window['-NOTIFYLINK-'].Update(endpointlink) else: settings_window['-NOTIFYLINK-'].Update('N/A') if event == '-NOTIFYLINK-' and values['-NOTIFY-']: # clicked on link import webbrowser link = settings_window['-NOTIFYLINK-'].DisplayText # send a welcome message notify = Notify() notify.send('Notifications will appear here.') webbrowser.open_new(link) continue ################################### ####### CREATE DATASET FLOW ####### ################################### if event in ('Create Dataset'): folder_path = sg.popup_get_folder("Please select the folder of flooded scalogram files", title="Select Folder for dataset") sg.popup('Creating dataset...Please wait') Dataset(folder_path) sg.popup('Dataset Created!') ######################### ####### GAN FLOW ######## ######################### if event in ('GAN'): main_window.close() main_window = None gan_window = None while True: if gan_window is None: gan_window = create_gan_window() else: break gan_event, gan_values = gan_window.read() if gan_event in (None, 'Quit', 'Cancel'): gan_window.close() break if gan_event.startswith('Generate'): # generate images gan_window.close() modelname = sg.popup_get_file("Please select a trained GAN model", title="Generate images from GAN model") if modelname in (None, 'Cancel'): gan_window = None continue plt_window = create_plt_window(modelname) fig = generate_images_grid(modelname) fig_canvas_agg = draw_figure(plt_window['-CANVAS-'].TKCanvas, fig) while True: plt_event, plt_values = plt_window.read() if plt_event in (None, 'Quit', 'Cancel', 'Ok'): plt_window.close() plt_window = None break if plt_event in ('New'): fig = generate_images_grid(modelname) fig_canvas_agg.get_tk_widget().pack_forget() fig_canvas_agg = draw_figure(plt_window['-CANVAS-'].TKCanvas, fig) _, _ = plt_window.read(timeout=10) continue if plt_event in ('Save'): namefile = sg.PopupGetFile('Enter filename', save_as=True) if namefile: try: fig.savefig(namefile) # plt_window.close() # plt_window = None sg.popup_quick_message('Image saved!', keep_on_top=True, auto_close_duration=2) time.sleep(2) except Exception as e: sg.popup('Error saving figure') if gan_event.startswith('Train'): # train new models gan_window.close() # select dataset file dataset = sg.popup_get_file("Please select a .npz dataset file", title="Train new GAN model: Load Dataset") if dataset in (None, 'Cancel'): gan_window = None continue gan_train_window = create_gan_train_window() gan_train_started = False thread = None while True: gt_event, gt_values = gan_train_window.read(timeout=10) if gt_event in (None, 'Quit', 'Cancel'): if gan_train_started: thread.join() gan_train_window.close() gan_train_window = None gan_train_started = False sg.popup_quick_message('Cancelled. Returning to main menu.', keep_on_top=True, auto_close_duration=2) time.sleep(2) break if gt_event in ('Start') and not gan_train_started: gan_train_main(dataset) gan_train_started = True # if gt_event in ('Start') and not gan_train_started: # try: # thread = threading.Thread(target=gan_train_main, args=(dataset,), daemon=True) # thread.start() # gan_train_started = True # except Exception as e: # print('Error starting thread: ', e) if event in ('Process Data'): main_window.close() # close main menu main_window = None #gc.collect() # boolean for showing warning message in load data layout select_folder_warning = False wav_only_warning = False load_data_popup = None while True: #pop up load window if load_data_popup is None: load_data_popup = create_load_data_popup(settings, wav_only_warning, select_folder_warning) else: break ld_event, ld_values = load_data_popup.read() #print('ld_event: %s\nld_values: %s' % (ld_event, ld_values)) if ld_event == 'Cancel': load_data_popup.close() # load_data_popup = None #gc.collect() break if ld_event in ('OK'): # clicked OK without selecting folder if ld_values['_FILES_']=='': load_data_popup.close() load_data_popup = None #gc.collect() select_folder_warning = True continue select_folder_warning = False # close load_data_popup load_data_popup.close() # load_data_popup = None #gc.collect() # print(ld_values) wave_dir = ld_values['_FILES_'].split(';')[0] print('### SELECTED FOLDER ###') print(wave_dir) print('### SELECTED FILES ###') # for file_name in os.listdir(wave_dir): # if file_name.endswith(".wav"): # print(file_name) # check for non .wav files in selected folder total_num_files = len(os.listdir(wave_dir)) total_num_wavs = len(glob.glob1(wave_dir, '*.wav')) # if non .wav files exist, warn user and return to load_data window wav_only_warning = total_num_files != total_num_wavs if not wav_only_warning: #create file storing wav file transformations if not os.path.exists('./png_scalogram'): os.mkdir('./png_scalogram') if not os.path.exists('./wav_transform'): os.mkdir('./wav_transform') png_sav_dir = './png_scalogram' wave_sav_dir = './wav_transform' ########################################################### ### PASS FILES TO DATA PIPELINE ### ########################################################### # print('SPLITTING\n') # org_wav = os.stat(wave_dir + "/test.wav") # print(f'File size in Bytes is {org_wav.st_size}') start = time.time() #TODO: add option to split wav files from GUI split_wav = True if (split_wav): WavPipeline.split(wave_dir, wave_sav_dir) stop = time.time() time_split= stop-start listwavs = os.listdir(wave_sav_dir) totalwavs = len(glob.glob1(wave_sav_dir, '*.wav')) i=1 size_wav = 0 size_scl = 0 size_png = 0 time_wavToScl = 0 time_sclToPng = 0 time_flood = 0 total_files = 0 try: for splitwav in listwavs: total_files += 1 except: print('################## CANNOT FIND FILES ################') exit(-1) pg_window = create_prog_bar_popup(settings, total_files) # create communicate queue if debug mode gui_queue = queue.Queue() # pg_window = sg.Window('File Processing').Layout(pg_layout) progress_bar = pg_window['progressbar_f'] process_count = pg_window['progressbar_p'] pg_window.read(timeout=10) process_count.UpdateBar(0) progress_bar.UpdateBar(0) pg_window['file_c'].update('(0/%d)' % total_files) pg_window['proc_c'].update('(0/%d)' % (total_files*3)) pg_window.read(timeout=10) # progress bar event loop started = False if multithreaded: print('MODE: MULTITHREADED') # multithreaded -- gui is responsive but may (will most definitely) crash while True: event, values = pg_window.read(timeout=100) if event in (None, 'Exit', 'Cancel'): print('CANCELLED, EXITING') pg_window.close() pg_window = None sg.popup_quick_message('Cancelled. Returning to main menu.', keep_on_top=True, auto_close_duration=1) time.sleep(1) break elif event.startswith('Start') and not started: # check for thread already spun up try: print('STARTING THREAD') thread = threading.Thread(target=main_op_thread, args=(listwavs, totalwavs, wave_sav_dir, png_sav_dir, total_files, gui_queue), daemon=True) thread.start() started = True except Exception as e: print('Error starting work thread') # elif event == 'Check responsive': # print('GUI is responsive') # check for incoming messages from thread try: message = gui_queue.get_nowait() except queue.Empty: message = None # check if message exists if message: # CHECK FOR SPECIFIC MESSAGES TO UPDATE PROGRESS BAR VALUES if isinstance(message, int) and message==42: thread.join() print('thread joined') pg_window.close() pg_window = None sg.popup_quick_message("Data Processing Complete", keep_on_top=True, auto_close_duration=2) time.sleep(2) break elif isinstance(message, str): # if string instance print it print(message) else: # otherwise, it is an opcode to update the progress bar print(message) proc_c_text = message[0] file_c_text = message[1] p_c = message[2] f_c = message[3] # update text pg_window['proc_c'].update(proc_c_text) pg_window['file_c'].update(file_c_text) # update bar process_count.UpdateBar(p_c) progress_bar.UpdateBar(f_c) else: print('MODE: SINGLETHREADED') # single threaded -- gui will not be responsive until each step is complete. event, values = pg_window.read() if event in (None, 'Exit', 'Cancel'): print('CANCELLED, EXITING') pg_window.close() pg_window = None sg.popup_quick_message('Cancelled. Returning to main menu.', keep_on_top=True, auto_close_duration=1) time.sleep(1) break elif event.startswith('Start') and not started: started = True # execute single-threaded processing pipeline main_data_process(listwavs, totalwavs, wave_sav_dir, png_sav_dir, total_files, pg_window) pg_window.close() pg_window = None sg.popup('Completion window', 'The provided data has successfully been processed!\nFind the results in your local directory.') # TODO: SEPARATELY CALL EACH FUNCTION IN THE PIPELINE # TODO: UPDATE THE GUI AND THE USER ON THE PROCESS OF EACH FUNCTION CALL # TODO: UPSCALE THE GUI SIZE SO IT IS NOT TIGHTLY FIT TO THE CURRENT GUI ELEMENTS -> MAKE IT MORE USER-FRIENDLY AND NAVIGABLE if ld_event in (None, 'Cancel'): load_data_popup.close() load_data_popup = None #gc.collect() break else: print('non .wav files detected') load_data_popup = None #gc.collect() if event in (None, 'Exit'): main_window.close() main_window = None