Exemple #1
0
def get_player(profile_id,
               report=None,
               category=None,
               force_refresh=False,
               save=True):
    profile_id = int(profile_id)
    player, created = Player.objects.get_or_create(profile_id=profile_id)
    now = datetime.datetime.now()
    if created or force_refresh:
        profile_data = scrape_profile(profile_id)
        player.name = profile_data[0]
        player.group_name = profile_data[1]
        player.join_date = profile_data[2]

    # Scrape player group info every 2 days
    elif now - player.scrape_date > datetime.timedelta(days=2):
        profile_data = scrape_profile(profile_id)
        player.group_name = profile_data[1]
    if report:
        report.players.add(player)
        CONN.sadd('rebuild', report.location_id)
    if category and not player.category:
        player.category = category
    if save:
        player.save()
    return player
Exemple #2
0
def get_player(profile_id, report=None, category=None, force_refresh=False):
    profile_id = int(profile_id)
    player, created = Player.objects.get_or_create(profile_id=profile_id)
    if created or force_refresh:
        profile_data = scrape_profile(profile_id)
        player.name = profile_data[0]
        player.group = profile_data[1]
        player.join_date = profile_data[2]

    # Scrape player group info every 14 days
    elif datetime.datetime.now() - player.scrape_date > datetime.timedelta(days=14):
        profile_data = scrape_profile(profile_id)
        player.group = profile_data[1]
    if report:
        report.players.add(player)
    if category and not player.category:
        player.category = category
    player.save()
    return player
Exemple #3
0
def get_player(profile_id, report=None, category=None, force_refresh=False):
    profile_id = int(profile_id)
    player, created = Player.objects.get_or_create(profile_id=profile_id)
    if created or force_refresh:
        profile_data = scrape_profile(profile_id)
        player.name = profile_data[0]
        player.group = profile_data[1]
        player.join_date = profile_data[2]

    # Scrape player group info every 14 days
    elif datetime.datetime.now() - player.scrape_date > datetime.timedelta(
            days=14):
        profile_data = scrape_profile(profile_id)
        player.group = profile_data[1]
    if report:
        report.players.add(player)
    if category and not player.category:
        player.category = category
    player.save()
    return player
Exemple #4
0
def import_user(profile_name_or_id, category=None, user=None, join_date=None):
    try:
        profile_id = int(profile_name_or_id)
    except ValueError:
        if user:
            message = "Couldn't create {}".format(profile_name_or_id)
            user.message_set.create(message=message)
        return

    info = scrape_profile(profile_id)

    player, created = Player.objects.get_or_create(profile_id=profile_id)
    if created:
        player.name = info[0]
        player.join_date = info[2]
    player.group_name = info[1]
    if not player.category:
        player.category = category
    player.save()