def handle_savegame(root, file):
  filename = os.path.join(root,file)
  print("Handling savegame: " + filename);
  txt = None;
  with lzma.open(filename,  mode="rt") as f:
    txt = f.read().split("\n");
    status.savegames_read += 1;

  new_filename = "pbem_processed_" + str(random.randint(0,10000000000)) + ".xz";
  f.close();
  shutil.move(filename, os.path.join(root,new_filename))
  print("New filename will be: " + new_filename);
  players = list_players(txt);
  phase = find_phase(txt);
  turn = find_turn(txt);
  game_id = find_game_id(txt);
  print("game_id=" + str(game_id));
  print("phase=" + str(phase));
  print("turn=" + str(turn));
  print("players=" + str(players));

  active_player = players[phase];
  print("active_player=" + active_player);    
  active_email = find_email_address(active_player);
  status.games[game_id] = [turn, phase, players, time.ctime()];
  if (active_email != None):
    print("active email=" + active_email);
    m = MailSender();
    m.send_email(active_player, players, active_email, new_filename.replace(".xz", ""), turn);
    status.emails_sent += 1;
def handle_savegame(root, file):
    time.sleep(1)
    filename = os.path.join(root, file)
    print("Handling savegame: " + filename)
    txt = None
    with lzma.open(filename, mode="rt") as f:
        txt = f.read().split("\n")
        status.savegames_read += 1

    new_filename = "pbem_processed_" + str(random.randint(0, 10000000000)) + ".xz"
    f.close()
    shutil.move(filename, os.path.join(root, new_filename))
    print("New filename will be: " + new_filename)
    players = list_players(txt)
    phase = find_phase(txt)
    turn = find_turn(txt)
    game_id = find_game_id(txt)
    state = find_state(txt)
    print("game_id=" + str(game_id))
    print("phase=" + str(phase))
    print("turn=" + str(turn))
    print("state=" + str(state))
    print("players=" + str(players))

    active_player = players[phase]
    print("active_player=" + active_player)
    active_email = find_email_address(active_player)
    status.games[game_id] = [turn, phase, players, time.ctime(), int(time.time()), state]
    if active_email != None:
        print("active email=" + active_email)
        m = MailSender()
        m.send_email(active_player, players, active_email, new_filename.replace(".xz", ""), turn)
        status.emails_sent += 1
Exemple #3
0
def handle_savegame(root, file):
  time.sleep(1);
  filename = os.path.join(root,file)
  print("Handling savegame: " + filename);
  txt = None;
  with lzma.open(filename,  mode="rt") as f:
    txt = f.read().split("\n");
    status.savegames_read += 1;

  new_filename = "pbem_processed_" + str(random.randint(0,10000000000)) + ".xz";
  f.close();
  shutil.move(filename, os.path.join(root,new_filename))
  print("New filename will be: " + new_filename);
  players = list_players(txt);
  phase = find_phase(txt);
  turn = find_turn(txt);
  game_id = find_game_id(txt);
  state = find_state(txt);
  print("game_id=" + str(game_id));
  print("phase=" + str(phase));
  print("turn=" + str(turn));
  print("state=" + str(state));
  print("players=" + str(players));

  active_player = players[phase];
  print("active_player=" + active_player);    
  active_email = find_email_address(active_player);
  status.games[game_id] = [turn, phase, players, time.ctime(), int(time.time()), state];
  if (active_email != None):
    print("active email=" + active_email);
    m = MailSender();
    m.send_email(active_player, players, active_email, new_filename.replace(".xz", ""), turn);
    status.emails_sent += 1;
Exemple #4
0
def get_orders_from_mongo():
    # Instantiate MongoDB connection context
    with MongoClient(mongo) as mongodb:
        # Connection to 'notify' collection of 'hh_orders' database
        collection = mongodb.hh_orders['notify']
        # Search for orders
        orders = list(collection.find({}))
        # Lists content of vacancies directory
        vacancies = get_reports_list('vacancies')
        # Lists content of resumes directory
        resumes = get_reports_list('resumes')

        if orders:
            for order in orders:
                # If it's vacancy order
                if order.get('occupation'
                             ) in vacancies and 'occupation' in order.keys():
                    # If completes successfully,
                    # notificates application admin and order customer
                    order_customer = order.get('customer')
                    mail = MailSender([mail_creds['admin'], order_customer],
                                      success, order.get('occupation'))
                    mail.send_email()
                    change_order_status(order)

                # If it's resume order
                if order.get(
                        'criteria') in resumes and 'criteria' in order.keys():
                    # If completes successfully,
                    # notificates application admin and order customer
                    order_customer = order.get('customer')
                    mail = MailSender([mail_creds['admin'], order_customer],
                                      success, order.get('criteria'))
                    mail.send_email()
                    change_order_status(order)
Exemple #5
0
def add_order_to_mongo(email, occupation=None, criteria=None):
    # Instantiate MongoDB connection context
    with MongoClient(mongo) as mongodb:
        # Connection to 'orders' collection of 'hh_reports' database
        collection = mongodb.hh_reports['orders']
        # Put request order
        if occupation:
            # If vacancy request
            order = {'customer': email, 'occupation': occupation}
            # Add order to MongoDB
            collection.insert(order)
            # Send mail notification
            subject = 'Laboranalysis application gets the new order'
            # To admin, with above subject and 'order' body
            mail = MailSender( [mail_creds['admin']], 
                                subject, 
                                str(order) )
            mail.send_email()
        else:
            # If resume request
            order = {'customer': email, 'criteria': criteria}
            # Add order to MongoDB
            collection.insert(order)
            # Send mail notification
            subject = 'Laboranalysis application gets the new order'
            # To admin, with above subject and 'order' body
            mail = MailSender( [mail_creds['admin']], 
                                subject, 
                                str(order) )
            mail.send_email()
Exemple #6
0
def send_email_to_customer():
    # Message subject
    success = 'Ваш отчёт готов!'
    # Retrieve occupation name and email address
    order_customer, occupation = get_email_from_mongo()
    # Retrieve a hyperlink to the xlsx report file
    message = get_href_from_mongo(occupation)
    mail = MailSender([mail_creds['admin'], order_customer], success, message)
    mail.send_email()
Exemple #7
0
def start_resumes_analyze(order):
    # Try to make processing on geted order
    try:
        # Import our vacancy processing class
        from resumehandler import ResumeHandler
        resumes = ResumeHandler(order.get('criteria'))
        resumes.restore_resumes_from_mongo()
        resumes.analyze()
        resumes.store_results_to_xlsx()
        change_order_status(order)
    # If run into an issue, notificates application admin
    except:
        mail = MailSender([mail_creds['admin']], problem, str(order))
        mail.send_email()
    # If completes successfully, notificates application admin
    mail = MailSender([mail_creds['admin']], success, order.get('criteria'))
    mail.send_email()
Exemple #8
0
def start_parse(order):
    # Try to make processing on geted order
    try:
        # Import our vacancy processing class
        from resumehandler import ResumeHandler
        resumes = ResumeHandler(order.get('criteria'))
        # Start retrievement with delay
        resumes._resumes_retriever(delay=30, number=None)
        resumes.store_resumes_to_mongo()
        change_order_status(order)
    # If run into an issue, notificates application admin
    except:
        mail = MailSender([mail_creds['admin']], problem, str(order))
        mail.send_email()
    # If completes successfully, notificates application admin
    mail = MailSender([mail_creds['admin']], success, order.get('criteria'))
    mail.send_email()
Exemple #9
0
def start_request(order):
    # Try to make processing on geted order
    try:
        # Import our vacancy processing class
        from vacancyhandler import VacancyHandler
        vacancies = VacancyHandler(order.get('occupation'))
        # Start retrievement with delay
        vacancies._vacancies_retriever(delay=10, number=None)
        vacancies.store_vacancies_to_mongo()
        change_order_status(order)
    # If run into an issue, notificates application admin
    except:
        mail = MailSender([mail_creds['admin']], problem, str(order))
        mail.send_email()
    # If completes successfully, notificates application admin
    mail = MailSender([mail_creds['admin']], success, order.get('occupation'))
    mail.send_email()
Exemple #10
0
def start_request(order):
    # Try to make processing on geted order
    try:
        # Import our vacancy processing class
        from laboranalysis.vacancyhandler import VacancyHandler
        vacancies = VacancyHandler(order.get('occupation'))
        vacancies.analyze()
        vacancies.store_vacancies_to_mongo()
        vacancies.store_results_to_xlsx()
        change_order_status(order)
    # If run into an issue, notificates application admin
    except:
        mail = MailSender([mail_creds['admin']], problem, str(order))
        mail.send_email()
    # If completes successfully,
    # notificates application admin and order customer
    order_customer = order.get('customer')
    mail = MailSender([mail_creds['admin'], order_customer], success,
                      order.get('occupation'))
    mail.send_email()
Exemple #11
0
    'email': '*****@*****.**'} 

companies.append(database.Company(testcomp4))


#add the companies to the list of companies to send emails to
for company in companies:
    if company.tte_days in email_txts.keys():
        email_txts[company.tte_days]['company'].append(company)

for days in email_txts:
    for rec in email_txts[days]['company']:
        sender.add_recepient(rec.email)
        
    sender.set_message_from_txt(email_txts[days]['txt'])
    sender.send_email()
    sender.clear_recepients()
    sender.clear_message()

'''
with open('2wks.txt') as m:
    msgtxt = m.read()
print(f'{repr(msgtxt)}')


message = EmailMessage()

try: 
    server = smtplib.SMTP_SSL(smtphost, 465)
    server.ehlo()
    server.login(sender_email, sender_pw)
Exemple #12
0
def send_email_to_customer(order):
    # Message subject
    subject = 'Laboranalysis application gets the new order'
    # To admin, with above subject and 'order' body
    mail = MailSender([mail_creds['admin']], subject, str(order))
    mail.send_email()