class SpontitApi: __resource = None __emails = [] __phone_numbers = [] def __init__(self, id, key): # print("SpontitApi init") self.__resource = SpontitResource(id, key) #assert type(resource) == SpontitResource def push(self, msg): response = self.__resource.push(msg) print("msg:" + msg) print("Response=" + str(response)) def setTargets(self, phone_numbers=[], emails=[]): __emails = emails __phones = phone_numbers def simple_push_to_specific_phone_numbers_and_emails_example( self, content="no msg", phone_numbers=[], emails=[]): dbf = open(r"/home/pi/bin/logs/pydbgInPush.log", "w") dbug = "in api pushpython function: content=<" + content + ">\n" if phone_numbers is not None: np = len(phone_numbers) dbug += "sending to " + str(np) + " phone #(s)\n" for p in range(0, np): dbug += str(p + 1) + ". " + phone_numbers[p] + "\n" if emails is not None: ne = len(emails) dbug += "sending to " + str(ne) + " email(s)\n" for e in range(0, ne): dbug += str(e + 1) + ". " + emails[e] + "\n" dbf.write(dbug) dbf.close() """ Sends a push notification to phone numbers and emails. We link the user account to the phone numbers and emails defined, and then send a push via Spontit. The users linked **do not have to follow your account** to receive the push notification. They will have the option to follow you or report you for spam. If you are reported for spam multiple times, your account will be restricted. :return: """ response = self.__resource.push(push_content=content, push_to_phone_numbers=phone_numbers, push_to_emails=emails) # rsp = "Notification sent to:\nEmails: " + {str(emails)} # rsp += "\nPhone numbers: " + {str(phone_numbers)} print(response) return response
def expire_one_hour_after_schedule(self): """ Schedules a push notification for one hour from now, and then expires it one hour later. :return: The result of the call to push """ return self.__resource.push( "Hello, in 1 hour. Bye in 2.", schedule_time_stamp=int(time.time()) + 3600, expiration=SpontitResource.Expiration(days=0, hours=1, minutes=0))
def immediate_expiration_push(self): """ Sends a push notification and sets the expiration for the current time. Because our expiration function polls approximately every 15-30 minutes, the notification will delete within 30 minutes. :return: The result of the call to push """ return self.__resource.push("Hello, expire ASAP (within 15 minutes)", expiration=SpontitResource.Expiration( 0, 0, 0))
import pyautogui import time import subprocess import os import win32clipboard from spontit import SpontitResource #from spontit import Expiration #configuracion notificaciones al celular resource = SpontitResource( "nicolas_raffa5828", "AWUC4HVUGE22LBE4Q4H1EACX6KBHG3NJCL0EYJFGBRNCMBK634JR52ZG0REXD7ZXABYUUPMY6QJNF4VY495P85D236QV69NOGY34" ) # set clipboard data win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() #win32clipboard.SetClipboardText('testing 123') win32clipboard.CloseClipboard() #print(pyautogui.position()) filename = "EstadoTorrent.txt" booleano = True def update(): #time.sleep(60*5) #limpio text file f1 = open(filename, "r+")
import redis import spontit import requests from time import time, sleep from urllib.parse import urlparse from spontit import SpontitResource from datetime import datetime, timedelta url = urlparse(os.environ.get("REDIS_URL")) red = redis.Redis(host=url.hostname, port=url.port, username=url.username, password=url.password, ssl=True, ssl_cert_reqs=None) notify = SpontitResource('rtxscalping', os.environ['SPONTIT_KEY']) def scalp(): try: r = requests.get(os.environ['POWER_URL'] + str(time())) r = r.json() except requests.exceptions.RequestException as e: print(e) sys.stdout.flush() return "" for prod in r['Products']: if prod['StockCount'] > 0: if not red.exists('in_stock', prod['TitleSlug']): red.lpush('in_stock', prod['TitleSlug']) msg = """
mapping = self.__resource.get_display_name_to_channel_id_mapping() if 'data' in mapping: channel_id_to_invite_to = mapping['data'].get( new_channel_display_name, None) if channel_id_to_invite_to is not None: return self.__resource.get_invite_options( channel_id_to_invite_to) return {"errors": [{"message": "Channel not found."}]} def get_invite_options_for_my_main_account(self): """ Gets the invite options for your main channel. :return: The response """ return self.__resource.get_invite_options() if __name__ == "__main__": # Try an example... spontit_src = SpontitResource("my_username", "my_secret_key") example_instance = Examples(spontit_src) response = example_instance.simple_push_example() print("Simple push example result: " + str(response)) # ...or get right to pushing! response = spontit_src.push("Hello!!!") print("Result: " + str(response)) # To see documentation, run: help(SpontitResource)
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from twilio.rest import Client # push notifications from spontit import SpontitResource import time import smtplib import settings resource = SpontitResource(settings.SPONTIT_USERNAME, settings.SPONTIT_SECCRET_KEY) def login(driver): email = settings.PARENT_ACCESS_EMAIL password = settings.PARENT_ACCESS_PASSWORD driver.get("https://parents.ebnet.org/genesis/sis/view?gohome=true") # find login fields parent_access_email = driver.find_element(By.XPATH, '//*[@id="j_username"]') parent_access_password = driver.find_element(By.XPATH, '//*[@id="j_password"]')
from .models import Victim from django.http import HttpResponse, JsonResponse import calendar import time import fr import create_dataset ts = str(calendar.timegm(time.gmtime())) import requests import urllib.request, urllib.parse, urllib.error import os from PyDictionary import PyDictionary imgname = 'media/pictures/img.jpg' #spontit detailsa from spontit import SpontitResource resource = SpontitResource(os.getenv('SPONTIT_NAME'),os.getenv('SPONTIT_KEY')) from dotenv import load_dotenv load_dotenv() # OR, the same with increased verbosity load_dotenv(verbose=True) # OR, explicitly providing path to '.env' from pathlib import Path # python3 only env_path = Path('.') / '.env' load_dotenv(dotenv_path=env_path) def heatmap(request): return render(request, 'heatmap.html', {'gkey': os.getenv('GOOGLE_KEY')})
for func in example_functions: # Added time.sleep(1) because of the rate limit. Only one push per second per channel. # (e.g. You can have two pushes in the same second if each goes to a different channel.) # See rate_limit_example print(func.__name__) func() time.sleep(1) print("") if __name__ == "__main__": # Try an example... # Get your userId at spontit.com/profile # Get your secretKey at spontit.com/secret_keys spontit_src = SpontitResource("my_user_id", "my_secret_key") example_instance = Examples(spontit_src) push_response = example_instance.simple_push_example() print("Simple push example result: " + str(push_response)) # ...or be bold... example_instance.do_everything() # ...or get right to pushing! push_response = spontit_src.push("Hello!!!") print("Result: " + str(push_response)) # To see documentation, run: help(SpontitResource)
def get_538_trump_approval(): """ Gets the newest 538 approval/disapproval estimates for the most addicted gamblers. If there is a new update, send a push notification. :return: - """ # Get the HTML from the 538 website. html_str = get_html_str_from_url( "https://projects.fivethirtyeight.com/trump-approval-ratings", wait_to_open=False) html_str = str(html_str) time_stamp_p_str = get_section_from_html(str(html_str), "p", { "class": "timestamp" }).string # noinspection PyBroadException try: time_stamp_p_str = time_stamp_p_str[7:].strip() except Exception: print("Failed at parsing.") return # Get the time stamp of when the website was last updated. from_zone = tz.gettz(TIME_ZONE_538) to_zone = tz.gettz('UTC') date_538_last_updated = dateutil.parser.parse(time_stamp_p_str) utc = date_538_last_updated.replace(tzinfo=from_zone) utc_time_str = utc.astimezone(to_zone) epoch_time_stamp_538_last_updated = calendar.timegm( utc_time_str.timetuple()) # Get the most recent approval and disapproval ratings. d4 = utc_time_str.strftime("%Y-%m-%d") approve_front_to_split = f'"date":"{d4}","future":false,"subgroup":"All polls","approve_estimate":"' approve_end_to_split = '","approve_hi":"' disapprove_front_to_split = '","disapprove_estimate":"' disapprove_end_to_split = '","disapprove_hi":"' first_approve_str = html_str.split(approve_front_to_split)[1] approve = first_approve_str.split(approve_end_to_split)[0] disapprove_str = first_approve_str.split(disapprove_front_to_split)[1] disapprove = disapprove_str.split(disapprove_end_to_split)[0] # Construct the alert to send. alert = "NEW Trump Approval Ratings:\nApprove: " + str(round(float(approve), 2)) \ + "%\nDisapprove: " + str(round(float(disapprove), 2)) + "%" # Get the time last updated. try: f = open(UPDATE_TIME_FILE, "r") last = f.read() last_updated = int(last) except FileNotFoundError: last_updated = 0 # If an update is needed, send an update. # Determine if an update is needed by comparing the most recent update time on 538's website with our local record # of the last time we updated. if last_updated < epoch_time_stamp_538_last_updated: if SPONTIT_SECRET_KEY is None: raise Exception( "You must fill out your secret key at the top of the file. You can get a secret key and " "push for FREE at spontit.com/secret_keys.") resource = SpontitResource(SPONTIT_USER_ID, SPONTIT_SECRET_KEY) resource.push(alert, channel_id=SPONTIT_CHANNEL_TO_UPDATE) # Write the new most recent update time. f = open(UPDATE_TIME_FILE, "w") f.write(str(int(time.time()))) f.close()
def get_spontit_resource(): lines = open("username_and_key.txt").read().splitlines() resource = SpontitResource(lines[0], lines[1]) return resource
def __init__(self, id, key): # print("SpontitApi init") self.__resource = SpontitResource(id, key)