Exemplo n.º 1
0
def add_credentials(request, api_id, viewer_id, sid, secret):
    credentials = VKCredentials(api_id, viewer_id, secret, sid)
    credentials.test()
    if not credentials.is_valid():
        return {'errors': ['Credentials seems to be broken']}
    collection = VKCredentialsCollection(settings.VK_CREDENTIALS_FILE_PATH)
    collection.add_new_tested_credentials(credentials)
    collection.dump_to_disk()
    return {}
Exemplo n.º 2
0
def launch(scanner_classes, scan_intervals): 
    current_intervals = [0*s for s in scan_intervals]
    while True:
        credentials = VKCredentialsCollection(settings.VK_CREDENTIALS_FILE_PATH)
        if not credentials.get_credentials():
            print "No good credentials found, falling asleep"
            complainAndSleep()
            continue
        
        try:
            print "Useful credentials found: " + str(len(credentials.get_credentials()))
            crawler = VKCrawler(credentials)
            for index, time_left in enumerate(current_intervals):
                if time_left <= 0:
                    print "Launching " + str(scanner_classes[index])
                    scan_interval = scan_intervals[index]
                    current_intervals[index] = scan_interval
                    time_before = datetime.now()
                    if settings.DEBUG:
                        scanner_classes[index]().scan(crawler)
                    else:
                        try:
                            scanner_classes[index]().scan(crawler)
                        except Exception as e:
                            print "Scanner " + str(scanner_classes[index]) + " failure: " + str(e)
                    gc.collect()                
                    time_after = datetime.now()
                    seconds_passed = (time_after - time_before).total_seconds()
                    for i, v in enumerate(current_intervals):
                        current_intervals[i] = v - seconds_passed
                    scan_stat = ScanStats(time_taken=seconds_passed, scanner_class = scanner_classes[index].get_id())
                    scan_stat.save()
                    print "Scan completed in " + str(timedelta(seconds=seconds_passed))
                    print "Current timing: " + str(current_intervals)
                    print "Next scan of this type scheduled in " + str(timedelta(seconds=max(0, current_intervals[index])))
                    if (current_intervals[index] < 0):
                        send_mail("Hello, this is the mighty group spy. The scan interval is too short. You should consider increasing it or supplying more credentials via http://vkontakte.ru/app2673575.", settings.COMPLAIN_TO)
            min_time = min(current_intervals)
            if min_time > 0:
                print "sleeping for " + str(timedelta(seconds=min_time))
                sleep(min_time)
                for i, v in enumerate(current_intervals):
                    current_intervals[i] = v - min_time
        except LogError:
            complainAndSleep()
            continue
Exemplo n.º 3
0
def delete_credentials(request, viewer_id, api_id):
    collection = VKCredentialsCollection(settings.VK_CREDENTIALS_FILE_PATH)
    collection.remove_credentials_by_viewer(viewer_id, api_id)
    collection.dump_to_disk()
    return {}
    
Exemplo n.º 4
0
def get_credentials(request):
    collection = VKCredentialsCollection(settings.VK_CREDENTIALS_FILE_PATH)
    all_credentials = [c.as_dictionary() for c in collection.get_all_credentials()]
    return all_credentials