コード例 #1
0
def show_ads(args):
    """
    Print list of all ads
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    [print("{} '{}'".format(adId, adName)) for adName, adId in api.get_all_ads()]
コード例 #2
0
def delete_ad(args, api=None):
    """
    Delete ad
    """
    [data, _] = get_post_details(args.ad_file)
    get_username_if_needed(args, data)

    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)

    if args.ad_file:
        del_ad_name = ""
        del_ad_category = -1
        for item in data:
            if item == "postAdForm.title":
                del_ad_name = data[item]
            if item == "categoryId":
                del_ad_category = data[item]
        try:
            api.delete_ad_using_title(del_ad_name, del_ad_category)
            print("Deletion successful or unaffected")
        except kijiji_api.KijijiApiException:
            print(
                "Did not find an existing ad with matching title, skipping ad deletion"
            )
コード例 #3
0
def delete_ad(args):
    """
    Delete ad
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    api.delete_ad(args.id)
コード例 #4
0
def check_ad(args, api=None):
    """
    Check if ad is live
    """
    [data, _] = get_post_details(args.ad_file)

    if not api:
        get_username_if_needed(args, data)
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)

    ad_title = ""
    ad_category = -1

    for key, val in data.items():
        if key == "postAdForm.title":
            ad_title = val
        if key == "categoryId":
            ad_category = val

    all_ads = api.get_all_ads()
    return [
        ad['title'] for ad in all_ads
        if ad['title'] == ad_title and ad['categoryId'] == ad_category
    ]
コード例 #5
0
def repost_ad(args, api=None):
    """
    Repost ad

    Try to delete ad with same title if possible before reposting new ad
    """
    [data, _] = get_post_details(args.ad_file)
    get_username_if_needed(args, data)

    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)

    del_ad_name = ""
    for item in data:
        if item == "postAdForm.title":
            del_ad_name = data[item]
    try:
        api.delete_ad_using_title(del_ad_name)
        print("Existing ad deleted before reposting")
    except kijiji_api.KijijiApiException:
        print("Did not find an existing ad with matching title, skipping ad deletion")
        pass

    # Must wait a bit before posting the same ad even after deleting it, otherwise Kijiji will automatically remove it
    print("Waiting 3 minutes before posting again. Please do not exit this script.")
    sleep(180)
    post_ad(args)
コード例 #6
0
def delete_ad(args, api=None):
    """
    Delete ad
    """
    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)
    api.delete_ad(args.id)
コード例 #7
0
def nuke(args):
    """
    Delete all active ads
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    all_ads = api.get_all_ads()
    [api.delete_ad(ad['id']) for ad in all_ads]
コード例 #8
0
def nuke(args):
    """
    Delete all ads
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    allAds = api.get_all_ads()
    [api.delete_ad(adId) for adName, adId in allAds]
コード例 #9
0
def post_ad(args):
    """
    Post new ad
    """
    [data, imageFiles] = get_inf_details(args.inf_file)
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    api.post_ad_using_data(data, imageFiles)
コード例 #10
0
def repost_all(args, api=None):
    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)

    all_ads_old = api.get_all_ads()
    [api.delete_ad(ad['@id']) for ad in all_ads_old]
    sleep(60)
    [api.post_ad_using_data(api.scrape_ad(ad), []) for ad in all_ads_old]
コード例 #11
0
def nuke(args, api=None):
    """
    Delete all active ads
    """
    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.ssid)
    all_ads = api.get_all_ads()
    [api.delete_ad(ad['id']) for ad in all_ads]
コード例 #12
0
def post_ad(args, api=None):
    """
    Post new ad
    """
    [data, image_files] = get_post_details(args.ad_file)
    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.ssid)

    attempts = 1
    while not check_ad(args, api) and attempts < 5:
        if attempts > 1:
            print("Failed ad post attempt #{}, trying again.".format(attempts))
        attempts += 1

        if not api:
            api = kijiji_api.KijijiApi()
            api.login(args.ssid)
        api.post_ad_using_data(data, image_files)
    if not check_ad(args, api):
        print("Failed ad post attempt #{}, giving up.".format(attempts))
コード例 #13
0
def check_ad(args):
    """
    Check if ad is live
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    AdName = ""
    for line in open(args.inf_file, 'rt'):
        [key, val] = line.strip().rstrip("\n").split("=")
        if key == "postAdForm.title":
            AdName = val
    allAds = api.get_all_ads()
    return [t for t, i in allAds if t == AdName]
コード例 #14
0
def show_ads(args):
    """
    Print list of all ads
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    all_ads = api.get_all_ads()
    print("    id    ", "page", "views", "          title")
    [
        print("{ad_id:10} {rank:4} {views:5} '{title}'".format(
            ad_id=ad['id'],
            rank=ad['rank'],
            views=ad['views'],
            title=ad['title'])) for ad in all_ads
    ]
コード例 #15
0
def post_ad(args):
    """
    Post new ad
    """
    [data, imageFiles] = get_inf_details(args.inf_file)
    attempts = 1
    while not check_ad(args) and attempts < 5:
        if attempts > 1:
            print("Failed Attempt #" + str(attempts) + ", trying again.")
        attempts += 1
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)
        api.post_ad_using_data(data, imageFiles)
        sleep(180)
    if not check_ad(args):
        print("Failed Attempt #" + str(attempts) + ", giving up.")
コード例 #16
0
def show_ads(args, api=None):
    """
    Print list of all ads
    """
    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)
    all_ads = sorted(api.get_all_ads(), key=lambda k: k[args.sort_key], reverse=args.sort_reverse)

    print("    id    ", "page", "views", "          title")
    [print("{ad_id:10} {rank:4} {views:5} '{title}'".format(
        ad_id=ad['id'],
        rank=ad['rank'],
        views=ad['views'],
        title=ad['title']
    )) for ad in all_ads]
コード例 #17
0
def check_ad(args):
    """
    Check if ad is live
    """
    [data, _] = get_post_details(args.ad_file)
    get_username_if_needed(args, data)

    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    ad_title = ""
    for key, val in data.items():
        if key == "postAdForm.title":
            ad_title = val
            break

    all_ads = api.get_all_ads()
    return [ad['title'] for ad in all_ads if ad['title'] == ad_title]
コード例 #18
0
def check_ad(args, api=None):
    """
    Check if ad is live
    """
    [data, _] = get_post_details(args.ad_file)

    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.ssid)

    ad_title = ""

    for key, val in data.items():
        if key == "postAdForm.title":
            ad_title = val

    all_ads = api.get_all_ads()
    return [ad['title'] for ad in all_ads if ad['title'] == ad_title]
コード例 #19
0
def post_ad(args):
    """
    Post new ad
    """
    [data, image_files] = get_post_details(args.ad_file)
    get_username_if_needed(args, data)

    attempts = 1
    while not check_ad(args) and attempts < 5:
        if attempts > 1:
            print("Failed ad post attempt #{}, trying again.".format(attempts))
        attempts += 1

        api = kijiji_api.KijijiApi()
        api.login(args.username, args.password)
        api.post_ad_using_data(data, image_files)
    if not check_ad(args):
        print("Failed ad post attempt #{}, giving up.".format(attempts))
コード例 #20
0
def delete_ad(args, api=None):
    """
    Delete ad
    """
    [data, _] = get_post_details(args.ad_file)

    if not api:
        api = kijiji_api.KijijiApi()
        api.login(args.ssid)

    if args.ad_file:
        del_ad_name = ""
        for item in data:
            if item == "postAdForm.title":
                del_ad_name = data[item]
        try:
            api.delete_ad_using_title(del_ad_name)
            print("Deletion successful or unaffected")
        except kijiji_api.KijijiApiException:
            print("Did not find an existing ad with matching title, skipping ad deletion")
コード例 #21
0
def post_ad(args, api=None):
    generator.run_program(args.ad_file)
    [data, image_files] = get_post_details(args.ad_file)
    get_username_if_needed(args, data)

    attempts = 1
    while not check_ad(args) and attempts < 5:
        if attempts > 1:
            print("Failed ad post attempt #{}, trying again.".format(attempts))
        attempts += 1

        if not api:
            api = kijiji_api.KijijiApi()
            print('Authenticating user..')
            api.login(args.username, args.password)
        api.post_ad_using_data(data, image_files)
    if not check_ad(args):
        print('Ad has been taken down :(')
        print("Failed ad post attempt #{}, giving up.".format(attempts))
    else:
        print('Ad is alive. Program will now exit.')
コード例 #22
0
def repost_ad(args):
    """
    Repost ad

    Try to delete ad with same title if possible before reposting new ad
    """
    api = kijiji_api.KijijiApi()
    api.login(args.username, args.password)
    delAdName = ""
    for line in open(args.inf_file, 'rt'):
        [key, val] = line.strip().rstrip("\n").split("=")
        if key == "postAdForm.title":
            delAdName = val
    try:
        api.delete_ad_using_title(delAdName)
        print("Existing ad deleted before reposting")
    except kijiji_api.DeleteAdException:
        print("Did not find an existing ad with matching title, skipping ad deletion")
        pass
    # Must wait a bit before posting the same ad even after deleting it, otherwise Kijiji will automatically remove it
    sleep(180)
    post_ad(args)
コード例 #23
0
def delete_ad_using_title(name):
    """
    Delete ad based on ad title
    """
    api = kijiji_api.KijijiApi()
    api.delete_ad_using_title(name)