Example #1
0
def add_telegram_update_job(state_id, telegram_id, resource_type):
    """Add telegram update job"""
    SCHEDULER.add_job(jobs.send_telegram_update,
                      'cron',
                      args=[state_id, telegram_id, resource_type],
                      id='{}_send_telegram_update_{}'.format(
                          state_id, resource_type),
                      replace_existing=True,
                      minute='5')
def add_send_lotery_message(state_id, department_type, language, amount):
    """Add send_message"""
    SCHEDULER.add_job(
        jobs.send_lotery_message,
        'cron',
        args=[state_id, department_type, language, amount],
        id='send_loter_message_{}_{}'.format(state_id, department_type),
        replace_existing=True,
        hour='8',
    )
def add_update_department(state_id, department_type):
    """Add jobs"""
    SCHEDULER.add_job(
        jobs.update_department,
        'cron',
        args=[state_id, department_type],
        id='{}_{}'.format(state_id, department_type),
        replace_existing=True,
        hour='19'
    )
Example #4
0
def add_update_factories(state_id):
    """Add jobs"""
    SCHEDULER.add_job(
        job_update_factories,
        'cron',
        args=[state_id],
        id='factories_{}'.format(state_id),
        replace_existing=True,
        hour='2,14'
    )
def add_send_progress_message(state_id, department_type, language):
    """Add send_message"""
    SCHEDULER.add_job(
        jobs.send_progress_message,
        'cron',
        args=[state_id, department_type, language],
        id='send_progress_message_{}_{}'.format(state_id, department_type),
        replace_existing=True,
        hour='19',
        minute='10'
    )
Example #6
0
def schedule_orders():
    """start deep exploration orders"""
    LOGGER.info('Start schedule orders')
    orders = database.get_orders()
    for job in SCHEDULER.get_jobs():
        print(job)
        if 'deep_exploration' in job.id:
            job.remove()
    for order in orders:
        schedule_order(order)
    LOGGER.info('Finish schedule orders')
Example #7
0
def schedule_order(order):
    """start deep exploration order"""
    deep_exploration = database.get_active_deep_exploration(order.region_id)
    if deep_exploration is None:
        sync_deep_exploration(order.region_id)
        deep_exploration = database.get_active_deep_exploration(
            order.region_id)
    start_date = deep_exploration.until_date_time if deep_exploration else datetime.now(
    )
    max_seconds = 5  # 300
    random_seconds = random.randint(0, max_seconds)
    scheduled_date = start_date + timedelta(seconds=random_seconds)
    LOGGER.info('%s: schedule deep exploration at %s for %s', order.region_id,
                scheduled_date.strftime("%Y-%m-%d %H:%M:%S"),
                RESOURCE_IDS[order.resource_type])
    SCHEDULER.add_job(jobs.start_deep_exploration_order,
                      'date',
                      args=[order.id],
                      id='deep_exploration_{}_{}'.format(
                          order.region_id, order.resource_type),
                      replace_existing=True,
                      run_date=scheduled_date)
Example #8
0
def check_resources(state_id, capital_id, resource_id, do_refill, alt):
    """Check resources and refill if necessary"""
    regions = api.download_resources(state_id, resource_id)
    LOGGER.info('state %6s: check resource %s', state_id,
                RESOURCE_IDS[resource_id])
    print_resources(regions, resource_id)
    refill_percentage = 25
    database.save_resources(state_id, regions, resource_id)
    if do_refill and need_refill(regions, refill_percentage):
        max_seconds = max_refill_seconds(regions, refill_percentage, 900)
        random_seconds = random.randint(0, max_seconds)
        random_time_delta = timedelta(seconds=random_seconds)
        scheduled_date = datetime.now() + random_time_delta
        job_id = 'refill_{}_{}'.format(capital_id, resource_id)
        LOGGER.info('state %s: refil resource %s at %s (%s minutes)', state_id,
                    RESOURCE_IDS[resource_id], scheduled_date,
                    round(random_time_delta.seconds / 60))
        job = SCHEDULER.get_job(job_id)
        if not job:
            SCHEDULER.add_job(jobs.refill_resource,
                              'date',
                              args=[state_id, capital_id, resource_id, alt],
                              id=job_id,
                              run_date=scheduled_date)
Example #9
0
    # get_resources(4001, datetime.now(), 0)
    # jobs.send_telegram_update(2788, '@vn_resources', 'gold')
    # jobs.send_telegram_update(2788, '@vn_uranium_resources', 'uranium')
    # sys.exit()

    JOBS = job_storage.get_jobs()
    for job in JOBS:
        LOGGER.info('Add check for "%s", resource "%s" at "%s", alt "%s"',
                    job['state_id'], job['resource_type'], job['minutes'],
                    job['alt'])
        SCHEDULER.add_job(jobs.check_resources,
                          'cron',
                          args=[
                              job['state_id'], job['capital_id'],
                              RESOURCE_NAMES[job['resource_type']],
                              job['refill'], job['alt']
                          ],
                          id='{}_check_{}'.format(job['state_id'],
                                                  job['resource_type']),
                          replace_existing=True,
                          minute=job['minutes'])

    add_telegram_update_job(3304, '@vn_resources', 'gold')
    add_telegram_update_job(3304, '@vn_uranium_resources', 'uranium')

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        LOGGER.info('Exiting application')
        SCHEDULER.shutdown()
Example #10
0
"""Main app"""

import time
import sys

from app import SCHEDULER, LOGGER, jobs

if __name__ == '__main__':
    LOGGER.info('Starting application')
    jobs.sync_deep_exploration(4002)
    # jobs.start_deep_exploration_order(2)
    sys.exit()

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        LOGGER.info('Exiting application')
        SCHEDULER.shutdown()
        sys.exit()
Example #11
0
"""Main app"""

import sys
import time

from app import SCHEDULER, LOGGER, jobs

if __name__ == '__main__':
    jobs.update_resource_market()

    LOGGER.info('Starting application')
    SCHEDULER.add_job(jobs.update_resource_market,
                      'cron',
                      id='job_update_resource_market',
                      replace_existing=True,
                      minute='0,10,20,30,40,50'
                      # minute='0,5,10,15,20,25,30,35,40,45,50,55'
                      )

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        LOGGER.info('Exiting application')
        SCHEDULER.shutdown()
        sys.exit()
    # jobs.send_progress_message(2788, 6, 'nl')
    # jobs.send_lotery_message(2788, 6, 'nl', 32e8)
    # sys.exit()

    # Jobs
    JOBS = job_storage.get_jobs()
    for job in JOBS:
        LOGGER.info(
            'For "%s" add department "%s" update',
            job['state_id'],
            job['department_type']
        )
        SCHEDULER.add_job(
            jobs.update_department,
            'cron',
            args=[job['state_id'], job['department_type']],
            id='{}_{}'.format(job['state_id'], job['department_type']),
            replace_existing=True,
            hour='19'
        )

    # progress message VN uranium
    add_send_progress_message(2788, 6, 'nl')
    add_send_lotery_message(2788, 6, 'nl', 36e8)

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        print('Exiting application')
        SCHEDULER.shutdown()
        sys.exit()
Example #13
0
import time

from app import SCHEDULER, LOGGER, jobs, job_storage

if __name__ == '__main__':
    # jobs
    # jobs.update_regions(2981)
    # sys.exit()

    # Jobs
    JOBS = job_storage.get_jobs()
    for state_id in JOBS:
        LOGGER.info(
            '"%s" add update job',
            state_id,
        )
        SCHEDULER.add_job(jobs.update_regions,
                          'cron',
                          args=[state_id],
                          id='{}_update_regions'.format(state_id),
                          replace_existing=True,
                          hour='12')

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        print('Exiting application')
        SCHEDULER.shutdown()
        sys.exit()
        4008,  # Amsterdam
        4101,  # Vlaanderen
        4102,  # Walonie
        4103,  # Brussel
        200062,  # Maan regio 62
    ]

    # jobs
    # jobs.update_citizens(STATE_IDS, REGION_IDS)
    # jobs.update_residents(STATE_IDS, REGION_IDS)
    # jobs.update_work_permits(STATE_IDS)

    # Update citizens
    SCHEDULER.add_job(jobs.update_citizens,
                      'cron',
                      args=[STATE_IDS, REGION_IDS],
                      id='update_citizens',
                      replace_existing=True,
                      hour='1,3,5,7,9,11,13,15,17,19,21,23')
    # Update residents
    SCHEDULER.add_job(jobs.update_residents,
                      'cron',
                      args=[STATE_IDS, REGION_IDS],
                      id='residents',
                      replace_existing=True,
                      hour='1,4,7,10,13,16,19,22')
    # Work permits
    SCHEDULER.add_job(jobs.update_work_permits,
                      'cron',
                      args=[STATE_IDS],
                      id='work_permits',
                      replace_existing=True,
"""Main app"""

import time
import sys

from app import SCHEDULER, LOGGER, jobs

if __name__ == '__main__':
    LOGGER.info('Starting application')
    # jobs.sync_deep_exploration(4002)
    # jobs.start_deep_exploration_order(2)
    # sys.exit()

    jobs.schedule_orders()
    # backup job to reschedule orders
    SCHEDULER.add_job(jobs.schedule_orders,
                      'cron',
                      id='schedule_orders',
                      hour='3')

    try:
        while True:
            time.sleep(100)
    except KeyboardInterrupt:
        LOGGER.info('Exiting application')
        SCHEDULER.shutdown()
        sys.exit()