Exemple #1
0
def post_to_vk(public, message, attachments):
    vk.method('wall.post', {'owner_id': -int(public), 'from_group': 1, 'message': message, 'attachments': attachments})


def poster():
    print 'poster!'
    while db['queue'].find().count() > 0:
        to_post = [x for x in db['queue'].find(sort=[("_id", -1)])]
        post_to_vk(to_post[0]['public_id'], to_post[0]['message'], to_post[0]['attachments'])
        db['queue'].remove({'_id': to_post[0]['_id']})
        time.sleep(11)  # waiting for posting without captcha


def clean_old():
    print 'cleaner!'
    for item in reposts:
        cur_public = str(item['public_id'])
        while db[cur_public].find().count() > 300:  # saving 300 latest entries
            to_remove = [x for x in db[cur_public].find(sort=[("_id", 1)])]
            db[cur_public].remove({'_id': to_remove[0]['_id']})

clean_old()
sched = Scheduler()
start_date = datetime.now() + timedelta(seconds=80)
sched.add_interval_job(parser, seconds=100, start_date=start_date)
sched.add_interval_job(poster, seconds=100)
sched.add_interval_job(clean_old, days=1, start_date=start_date)
sched.standalone = True
sched.start()
Exemple #2
0
    print('poster!')
    while db['queue'].find().count() > 0:
        to_post = [x for x in db['queue'].find(sort=[("_id", -1)])]
        post_to_vk(to_post[0]['public_id'], to_post[0]['message'],
                   to_post[0]['attachments'])
        db['queue'].remove({'_id': to_post[0]['_id']})
        time.sleep(11)  # waiting for posting without captcha


def clean_old():
    """
    cleaning database

    """
    print('cleaner!')
    for item in reposts:
        cur_public = str(item['public_id'])
        while db[cur_public].find().count() > 300:  # saving 300 latest entries
            to_remove = [x for x in db[cur_public].find(sort=[("_id", 1)])]
            db[cur_public].remove({'_id': to_remove[0]['_id']})


clean_old()
sched = Scheduler()
start_date = datetime.now() + timedelta(seconds=80)
sched.add_interval_job(parser, seconds=100, start_date=start_date)
sched.add_interval_job(poster, seconds=100)
sched.add_interval_job(clean_old, days=1, start_date=start_date)
sched.standalone = True
sched.start()