Example #1
0
def check_api():
	try:
		response = requests.get(url, timeout=timeout_in_sec)	# GET response is being made here.
		response_status = response.ok
	except:
		response_status = False

	# Compare the current response status with the previous API status.
	status = file_util.get_status()
	old_status = status.get_api_status()
	if response_status:	# Previous status is OK.
		if status.get_temp_status() == api_status.OK:
			status.set_status_count(status.get_status_count() + 1)
			if status.get_status_count() >= 2: # This may lead to Status transition.
				status.set_api_status(api_status.OK)
		else:	# Temp status has changed.
			status.set_temp_status(api_status.OK)
			status.set_status_count(1)

	else:	# Previous status is FAILED.
		if status.get_temp_status() == api_status.FAILED:
			status.set_status_count(status.get_status_count() + 1)
			if (status.get_status_count() >= 3):	# This may lead to Status transition.
				status.set_api_status(api_status.FAILED)
		else:	# Temp status has changed.
			status.set_temp_status(api_status.FAILED)
			status.set_status_count(1)

	file_util.set_status(status)	# Update the status for next run.
	if status.get_api_status() != old_status:	# Status has transitioned.
		mail_util.send_mail(status)
Example #2
0
 def save_and_send(title, x, r, b):
     path = '../../logs/plot.png'
     fig = plt.figure()
     plt.title(title)
     plt.xlabel('time steps')
     plt.plot(x, r, label='rewards')
     plt.plot(x, b, label='best rewards')
     plt.legend()
     fig.savefig(path)
     sleep(5)
     send_mail('Plot of rewards and best rewards', path, Config())
Example #3
0
 def post(self):
     try:
         parser = RequestParser()
         parser.add_argument('email', type=str)
         parser.add_argument('token', type=str)
         args = parser.parse_args()
         pwd = ''.join(choice(ascii_uppercase) for i in range(8))
         salted_string = (pwd + SALT)
         hashed_pwd = hash_sha(salted_string)
         UserService.create_user(args['email'], hashed_pwd, args['token'])
         send_mail(args['email'], "Account information",
                   "Hi, This is your temporary password for your account: " + pwd)
         return {'message': 'ok'}
     except:
         return {'message': 'error'}
Example #4
0
 def post(self):
     try:
         parser = RequestParser()
         parser.add_argument('email', type=str)
         parser.add_argument('token', type=str)
         args = parser.parse_args()
         pwd = ''.join(choice(ascii_uppercase) for i in range(8))
         salted_string = (pwd + SALT)
         hashed_pwd = hash_sha(salted_string)
         UserService.create_user(args['email'], hashed_pwd, args['token'])
         send_mail(
             args['email'], "Account information",
             "Hi, This is your temporary password for your account: " + pwd)
         return {'message': 'ok'}
     except:
         return {'message': 'error'}
Example #5
0
 def plot(self, rewards, test_rewards, eps_n):
     torch.save({
         'train_rewards': rewards,
         'test_rewards': test_rewards
     }, f'{self.plot_folder}/{eps_n}.pth')
     figure = plt.figure()
     plt.plot(rewards, label='Train Rewards')
     plt.plot(test_rewards, label='Test Rewards')
     plt.xlabel('Episode')
     plt.legend()
     plt.savefig(f'{self.plot_folder}/{eps_n}.png')
     try:
         send_mail(f'Improved Torcs SAC | Episode {eps_n}',
                   f'{self.plot_folder}/{eps_n}.png')
         log('Mail has been sent.')
     except (KeyboardInterrupt, SystemExit):
         print('KeyboardInterrupt or SystemExit')
         raise
     except Exception as e:
         print('Mail Exception occured:', e)
         emsg = e.args[-1]
         emsg = emsg[:1].lower() + emsg[1:]
         log('Couldn\'t send mail because', emsg)
Example #6
0
#!/usr/bin/python
import client as open_jub
import getpass
import mail_util
from expected_errors import *

if __name__ == '__main__':
  token = None

  while token == None:
    try:
      user = raw_input('Username: ')
      pwd = getpass.getpass()
      token = open_jub.login(user, pwd)
    except LoginException as e:
      print e

  print "Logged in! Token: %s" % token

  me = open_jub.get_user("kkafadarov")
  sender = "*****@*****.**"
  data = "Hey boo"
  title = "Test"

  print mail_util.send_mail(me, sender, data, title)
  print open_jub.is_authenticated(token)
Example #7
0
#!/usr/bin/python
import client as open_jub
import getpass
import mail_util
from expected_errors import *

if __name__ == '__main__':
    token = None

    while token == None:
        try:
            user = raw_input('Username: ')
            pwd = getpass.getpass()
            token = open_jub.login(user, pwd)
        except LoginException as e:
            print e

    print "Logged in! Token: %s" % token

    me = open_jub.current_user()
    sender = "*****@*****.**"
    data = "Hey boo"
    title = "Test"

    print mail_util.send_mail(me, sender, data, title)
import dbstruct

if __name__ == "__main__":
    mail_server = mail_util.login("or2553","utosr!986")
    mail_content_base = open("mail_content_reminder1.txt", "r").read()

    (db,c) = dbstruct.openDb()
    c.execute("SELECT * FROM login WHERE cid not like 'TEST%%' and cid not like 'vTEST%%' and cid not like 'bTEST%%' and cid not like 'otest%%' and cid not in (select cid from result where lastnode = '11' or lastnode = '10')")
    #c.execute("SELECT * FROM login WHERE cid like 'btest%' or cid like 'vtest%' or cid like 'otest%'")
    #c.execute("SELECT * FROM login WHERE cid like 'Test31'")
    mailing_list = c.fetchall()
    
    #print mailing_list, len(mailing_list)
    #sys.exit(0)
    
    for mailing_element in mailing_list:
        cid = mailing_element[0]
        to_id = mailing_element[3]
        
        if to_id == "EMPTY":
            continue
            
        print cid, to_id

        mail_content = mail_content_base.replace("USERID", cid);
        
        mail_util.send_mail(mail_server, "Office of Survey Research<*****@*****.**>",to_id,"Killeen ISD Climate Survey", mail_content, "")
        print "Done mailing... %s %s"%(cid, to_id)
        
    mail_util.logout(mail_server)