def add_person(): body = request.get_json() q.enqueue(body['name'], body['number']) send_msg( body['number'], body['name'] + ", you are in queeue, we'll let you know when you are next.") return jsonify(q.get_queue()), 200
def sms(): name = request.form['Body'] number = request.form['From'] q.enqueue(name, number) # Unable to create record: The number is unverified. Trial accounts cannot send messages to # unverified numbers; verify at twilio.com/user/account/phone-numbers/verified, or purchase a # Twilio number to send messages to unverified numbers. send_msg(number, 'Hello ' + name + ', you are now on the waiting list.') return 'ok', 200
def send(self): line = self.text_area.get('0.0', tk.END) st = self.prof["text"] if not line: self.status_text["text"] = "Empty message!" if st == "No Profanity detected": self.status_text["text"] = "Sending..." try: send_sms.send_msg(self.text_area.get('0.0', tk.END), self.phone.get()) self.status_text["text"] = "Sent." except Exception as e: self.status_text["text"] = "Cannot send." print(e) elif st == "Profanity detected": self.status_text["text"] = "Cannot send. Contains Profanity!"
def get_stock(resolution): # Retry on Failure for finnhub API call limit retry_strategy = Retry(total=20, status_forcelist=[429], method_whitelist=["GET"], backoff_factor=1) adapter = HTTPAdapter(max_retries=retry_strategy) http = requests.Session() http.mount("https://", adapter) http.mount("http://", adapter) # Connect to an existing databse conn = db_connect() # Open a cursor to perform database operations cur = conn.cursor() # Setup client api_key = os.environ['API_KEY'] # Stock symbol list symbols = pd.read_csv('/home/ubuntu/workspace/companylist.csv') symbols = symbols['Symbol'] # Setup time # Initializing the 20 years dataset # twenty_yr = relativedelta(years=20) # end = datetime.now().timestamp() # start = (datetime.fromtimestamp(end) - twenty_yr).timestamp() # To get the past one day daily data one_day = relativedelta(hours=24) end = datetime.now().timestamp() start = (datetime.now() - one_day).timestamp() try: for symbol in symbols: # Stock candles api_link = 'https://finnhub.io/api/v1/stock/candle?' \ + 'symbol={symbol}&resolution={resolution}&from={from_t}' \ + '&to={to_t}&token={token}' endpoint = api_link.format(symbol=symbol, resolution=resolution, from_t=str(int(start)), to_t=str(int(end)), token=api_key) response = http.get(endpoint) response_dict = json.loads(response.content.decode('utf-8')) if response_dict.get('s') == 'ok': # Convert to Pandas Dataframe and display datetime stock_candles = pd.DataFrame.from_dict(response_dict) stock_candles['s'] = 'ok' stock_candles['dt'] = [ datetime.fromtimestamp(t) for t in stock_candles['t'] ] stock_candles.drop('t', axis=1, inplace=True) stock_candles['symbol'] = symbol # Convert UTC to EST stock_candles['dt'] = stock_candles['dt'].dt.tz_localize( 'UTC').dt.tz_convert('US/Eastern') # Export to csv buffer = StringIO() stock_candles.to_csv(buffer, index=False, header=False) buffer.seek(0) # Copying the data from csv cur.copy_from(buffer, 'stock_candles_daily', sep=',') conn.commit() else: print('Sorry, no valid data for ' + symbol + ' at this moment') cur.close() send_msg('COMPLETED') except: send_msg('ALERT') return
def process(): person = q.dequeue() send_msg(person['number'], person['name'] + ', you are next.') return 'ok', 200
def handle_post(): body = request.get_json() send_msg(body['message']) return jsonify({'msg': 'message sent'}), 200
def handle_get(): send_msg() return jsonify({'msg': 'message sent'}), 200